| Differences between
and this patch
- a/Source/WebCore/ChangeLog +31 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2016-04-25  Frederic Wang  <fwang@igalia.com>
2
3
        Introduce MathOperator::OperatorType
4
        https://bugs.webkit.org/show_bug.cgi?id=156950
5
6
        Reviewed by NOBODY (OOPS!).
7
8
        No new tests, behavior is not change.
9
10
        An enum OperatorType is introduced in MathOperator in order to indicate
11
        which kind of stretching is requested. In follow-up work, this will
12
        allow to just call setOperator and stretchTo without having to
13
        explicitly call calculateDisplayStyleLargeOperator or calculateStretchyData.
14
15
        * rendering/mathml/MathOperator.cpp:
16
        (WebCore::MathOperator::MathOperator): Use OperatorType instead of a boolean.
17
        (WebCore::MathOperator::setOperator): Ditto.
18
        (WebCore::MathOperator::setGlyphAssembly): Add an assert to ensure that the function is correctly used.
19
        (WebCore::MathOperator::calculateDisplayStyleLargeOperator): Ditto, this makes the assert more accurate.
20
        (WebCore::MathOperator::calculateStretchyData): Ditto and replace m_isVertical with a local isVertical variable.
21
        (WebCore::MathOperator::fillWithVerticalExtensionGlyph): Ditto.
22
        (WebCore::MathOperator::fillWithHorizontalExtensionGlyph): Ditto.
23
        (WebCore::MathOperator::paintVerticalGlyphAssembly): Ditto.
24
        (WebCore::MathOperator::paintHorizontalGlyphAssembly): Ditto.
25
        * rendering/mathml/MathOperator.h: Add the OperatorType enum.
26
        (WebCore::MathOperator::stretchSize): Use OperatorType instead of a boolean and add an
27
        assert to ensure that the function is correctly used.
28
        * rendering/mathml/RenderMathMLOperator.cpp:
29
        (WebCore::RenderMathMLOperator::computePreferredLogicalWidths): Call setOperator with the correct value.
30
        (WebCore::RenderMathMLOperator::updateStyle): Ditto.
31
1
2016-04-22  Frederic Wang  <fwang@igalia.com>
32
2016-04-22  Frederic Wang  <fwang@igalia.com>
2
33
3
        Move selection and drawing of stretchy operators into a separate MathOperator class
34
        Move selection and drawing of stretchy operators into a separate MathOperator class
- a/Source/WebCore/rendering/mathml/MathOperator.cpp -15 / +18 lines
Lines 77-83 static const StretchyCharacter stretchyCharacters[14] = { a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec1
77
77
78
MathOperator::MathOperator()
78
MathOperator::MathOperator()
79
    : m_baseCharacter(0)
79
    : m_baseCharacter(0)
80
    , m_isVertical(false)
80
    , m_operatorType(OperatorType::UndefinedOperator)
81
    , m_stretchType(StretchType::Unstretched)
81
    , m_stretchType(StretchType::Unstretched)
82
    , m_width(0)
82
    , m_width(0)
83
    , m_ascent(0)
83
    , m_ascent(0)
Lines 86-95 MathOperator::MathOperator() a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec2
86
{
86
{
87
}
87
}
88
88
89
void MathOperator::setOperator(UChar baseCharacter, bool isVertical)
89
void MathOperator::setOperator(UChar baseCharacter, OperatorType operatorType)
90
{
90
{
91
    m_baseCharacter = baseCharacter;
91
    m_baseCharacter = baseCharacter;
92
    m_isVertical = isVertical;
92
    m_operatorType = operatorType;
93
}
93
}
94
94
95
bool MathOperator::getBaseGlyph(const RenderStyle& style, GlyphData& baseGlyph) const
95
bool MathOperator::getBaseGlyph(const RenderStyle& style, GlyphData& baseGlyph) const
Lines 107-119 void MathOperator::setSizeVariant(const GlyphData& sizeVariant) a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec3
107
107
108
void MathOperator::setGlyphAssembly(const GlyphAssemblyData& assemblyData)
108
void MathOperator::setGlyphAssembly(const GlyphAssemblyData& assemblyData)
109
{
109
{
110
    ASSERT(m_operatorType == OperatorType::VerticalOperator || m_operatorType == OperatorType::HorizontalOperator);
110
    m_stretchType = StretchType::GlyphAssembly;
111
    m_stretchType = StretchType::GlyphAssembly;
111
    m_assembly = assemblyData;
112
    m_assembly = assemblyData;
112
}
113
}
113
114
114
void MathOperator::calculateDisplayStyleLargeOperator(const RenderStyle& style)
115
void MathOperator::calculateDisplayStyleLargeOperator(const RenderStyle& style)
115
{
116
{
116
    ASSERT(m_isVertical);
117
    ASSERT(m_operatorType == OperatorType::DisplayOperator);
117
118
118
    GlyphData baseGlyph;
119
    GlyphData baseGlyph;
119
    if (!getBaseGlyph(style, baseGlyph) || !baseGlyph.font->mathData())
120
    if (!getBaseGlyph(style, baseGlyph) || !baseGlyph.font->mathData())
Lines 241-247 bool MathOperator::calculateGlyphAssemblyFallBack(const RenderStyle& style, cons a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec4
241
242
242
void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximumGlyphWidth, LayoutUnit targetSize)
243
void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximumGlyphWidth, LayoutUnit targetSize)
243
{
244
{
244
    ASSERT(!maximumGlyphWidth || m_isVertical);
245
    ASSERT(m_operatorType == OperatorType::VerticalOperator || m_operatorType == OperatorType::HorizontalOperator);
246
    ASSERT(!maximumGlyphWidth || m_operatorType == OperatorType::VerticalOperator);
247
    bool isVertical = m_operatorType == OperatorType::VerticalOperator;
245
248
246
    GlyphData baseGlyph;
249
    GlyphData baseGlyph;
247
    if (!getBaseGlyph(style, baseGlyph))
250
    if (!getBaseGlyph(style, baseGlyph))
Lines 249-255 void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximu a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec5
249
252
250
    if (!maximumGlyphWidth) {
253
    if (!maximumGlyphWidth) {
251
        // We do not stretch if the base glyph is large enough.
254
        // We do not stretch if the base glyph is large enough.
252
        float baseSize = m_isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph);
255
        float baseSize = isVertical ? heightForGlyph(baseGlyph) : advanceWidthForGlyph(baseGlyph);
253
        if (targetSize <= baseSize)
256
        if (targetSize <= baseSize)
254
            return;
257
            return;
255
    }
258
    }
Lines 258-264 void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximu a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec6
258
    if (baseGlyph.font->mathData()) {
261
    if (baseGlyph.font->mathData()) {
259
        Vector<Glyph> sizeVariants;
262
        Vector<Glyph> sizeVariants;
260
        Vector<OpenTypeMathData::AssemblyPart> assemblyParts;
263
        Vector<OpenTypeMathData::AssemblyPart> assemblyParts;
261
        baseGlyph.font->mathData()->getMathVariants(baseGlyph.glyph, m_isVertical, sizeVariants, assemblyParts);
264
        baseGlyph.font->mathData()->getMathVariants(baseGlyph.glyph, isVertical, sizeVariants, assemblyParts);
262
        // We verify the size variants.
265
        // We verify the size variants.
263
        for (auto& sizeVariant : sizeVariants) {
266
        for (auto& sizeVariant : sizeVariants) {
264
            GlyphData glyphData(sizeVariant, baseGlyph.font);
267
            GlyphData glyphData(sizeVariant, baseGlyph.font);
Lines 266-272 void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximu a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec7
266
                *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(glyphData));
269
                *maximumGlyphWidth = std::max(*maximumGlyphWidth, advanceWidthForGlyph(glyphData));
267
            else {
270
            else {
268
                setSizeVariant(glyphData);
271
                setSizeVariant(glyphData);
269
                float size = m_isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
272
                float size = isVertical ? heightForGlyph(glyphData) : advanceWidthForGlyph(glyphData);
270
                if (size >= targetSize)
273
                if (size >= targetSize)
271
                    return;
274
                    return;
272
            }
275
            }
Lines 276-282 void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximu a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec8
276
        if (!calculateGlyphAssemblyFallBack(style, assemblyParts, assemblyData))
279
        if (!calculateGlyphAssemblyFallBack(style, assemblyParts, assemblyData))
277
            return;
280
            return;
278
    } else {
281
    } else {
279
        if (!m_isVertical)
282
        if (!isVertical)
280
            return;
283
            return;
281
284
282
        // If the font does not have a MATH table, we fallback to the Unicode-only constructions.
285
        // If the font does not have a MATH table, we fallback to the Unicode-only constructions.
Lines 314-320 void MathOperator::calculateStretchyData(const RenderStyle& style, float* maximu a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec9
314
    }
317
    }
315
318
316
    // We ensure that the size is large enough to avoid glyph overlaps.
319
    // We ensure that the size is large enough to avoid glyph overlaps.
317
    float minSize = m_isVertical ?
320
    float minSize = isVertical ?
318
        heightForGlyph(assemblyData.topOrRight) + heightForGlyph(assemblyData.middle) + heightForGlyph(assemblyData.bottomOrLeft)
321
        heightForGlyph(assemblyData.topOrRight) + heightForGlyph(assemblyData.middle) + heightForGlyph(assemblyData.bottomOrLeft)
319
        : advanceWidthForGlyph(assemblyData.bottomOrLeft) + advanceWidthForGlyph(assemblyData.middle) + advanceWidthForGlyph(assemblyData.topOrRight);
322
        : advanceWidthForGlyph(assemblyData.bottomOrLeft) + advanceWidthForGlyph(assemblyData.middle) + advanceWidthForGlyph(assemblyData.topOrRight);
320
    if (minSize > targetSize)
323
    if (minSize > targetSize)
Lines 377-383 LayoutRect MathOperator::paintGlyph(const RenderStyle& style, PaintInfo& info, c a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec10
377
380
378
void MathOperator::fillWithVerticalExtensionGlyph(const RenderStyle& style, PaintInfo& info, const LayoutPoint& from, const LayoutPoint& to)
381
void MathOperator::fillWithVerticalExtensionGlyph(const RenderStyle& style, PaintInfo& info, const LayoutPoint& from, const LayoutPoint& to)
379
{
382
{
380
    ASSERT(m_isVertical);
383
    ASSERT(m_operatorType == OperatorType::VerticalOperator);
381
    ASSERT(m_stretchType == StretchType::GlyphAssembly);
384
    ASSERT(m_stretchType == StretchType::GlyphAssembly);
382
    ASSERT(m_assembly.extension.isValid());
385
    ASSERT(m_assembly.extension.isValid());
383
    ASSERT(from.y() <= to.y());
386
    ASSERT(from.y() <= to.y());
Lines 415-421 void MathOperator::fillWithVerticalExtensionGlyph(const RenderStyle& style, Pain a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec11
415
418
416
void MathOperator::fillWithHorizontalExtensionGlyph(const RenderStyle& style, PaintInfo& info, const LayoutPoint& from, const LayoutPoint& to)
419
void MathOperator::fillWithHorizontalExtensionGlyph(const RenderStyle& style, PaintInfo& info, const LayoutPoint& from, const LayoutPoint& to)
417
{
420
{
418
    ASSERT(!m_isVertical);
421
    ASSERT(m_operatorType == OperatorType::HorizontalOperator);
419
    ASSERT(m_stretchType == StretchType::GlyphAssembly);
422
    ASSERT(m_stretchType == StretchType::GlyphAssembly);
420
    ASSERT(m_assembly.extension.isValid());
423
    ASSERT(m_assembly.extension.isValid());
421
    ASSERT(from.x() <= to.x());
424
    ASSERT(from.x() <= to.x());
Lines 451-457 void MathOperator::fillWithHorizontalExtensionGlyph(const RenderStyle& style, Pa a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec12
451
454
452
void MathOperator::paintVerticalGlyphAssembly(const RenderStyle& style, PaintInfo& info, const LayoutPoint& paintOffset)
455
void MathOperator::paintVerticalGlyphAssembly(const RenderStyle& style, PaintInfo& info, const LayoutPoint& paintOffset)
453
{
456
{
454
    ASSERT(m_isVertical);
457
    ASSERT(m_operatorType == OperatorType::VerticalOperator);
455
    ASSERT(m_stretchType == StretchType::GlyphAssembly);
458
    ASSERT(m_stretchType == StretchType::GlyphAssembly);
456
    ASSERT(m_assembly.topOrRight.isValid());
459
    ASSERT(m_assembly.topOrRight.isValid());
457
    ASSERT(m_assembly.bottomOrLeft.isValid());
460
    ASSERT(m_assembly.bottomOrLeft.isValid());
Lines 483-492 void MathOperator::paintVerticalGlyphAssembly(const RenderStyle& style, PaintInf a/Source/WebCore/rendering/mathml/MathOperator.cpp_sec13
483
486
484
void MathOperator::paintHorizontalGlyphAssembly(const RenderStyle& style, PaintInfo& info, const LayoutPoint& paintOffset)
487
void MathOperator::paintHorizontalGlyphAssembly(const RenderStyle& style, PaintInfo& info, const LayoutPoint& paintOffset)
485
{
488
{
486
    ASSERT(!m_isVertical);
489
    ASSERT(m_operatorType == OperatorType::HorizontalOperator);
487
    ASSERT(m_stretchType == StretchType::GlyphAssembly);
490
    ASSERT(m_stretchType == StretchType::GlyphAssembly);
488
    ASSERT(m_assembly.bottomOrLeft.isValid());
489
    ASSERT(m_assembly.topOrRight.isValid());
491
    ASSERT(m_assembly.topOrRight.isValid());
492
    ASSERT(m_assembly.bottomOrLeft.isValid());
490
493
491
    // We are positioning the glyphs so that the edge of the tight glyph bounds line up exactly with the edges of our paint box.
494
    // We are positioning the glyphs so that the edge of the tight glyph bounds line up exactly with the edges of our paint box.
492
    LayoutPoint operatorTopLeft = paintOffset;
495
    LayoutPoint operatorTopLeft = paintOffset;
- a/Source/WebCore/rendering/mathml/MathOperator.h -3 / +8 lines
Lines 39-46 class RenderStyle; a/Source/WebCore/rendering/mathml/MathOperator.h_sec1
39
39
40
class MathOperator {
40
class MathOperator {
41
public:
41
public:
42
    enum class OperatorType { UndefinedOperator, DisplayOperator, VerticalOperator, HorizontalOperator };
42
    MathOperator();
43
    MathOperator();
43
    void setOperator(UChar baseCharacter, bool isVertical);
44
    void setOperator(UChar baseCharacter, OperatorType);
44
45
45
    LayoutUnit italicCorrection() const { return m_italicCorrection; }
46
    LayoutUnit italicCorrection() const { return m_italicCorrection; }
46
47
Lines 65-71 public: a/Source/WebCore/rendering/mathml/MathOperator.h_sec2
65
        TrimLeftAndRight
66
        TrimLeftAndRight
66
    };
67
    };
67
68
68
    LayoutUnit stretchSize() const { return m_isVertical ? m_ascent + m_descent : m_width; };
69
    LayoutUnit stretchSize() const
70
    {
71
        ASSERT(m_operatorType == OperatorType::VerticalOperator || m_operatorType == OperatorType::HorizontalOperator);
72
        return m_operatorType == OperatorType::VerticalOperator ? m_ascent + m_descent : m_width;
73
    }
69
    bool getBaseGlyph(const RenderStyle&, GlyphData&) const;
74
    bool getBaseGlyph(const RenderStyle&, GlyphData&) const;
70
    void setSizeVariant(const GlyphData&);
75
    void setSizeVariant(const GlyphData&);
71
    void setGlyphAssembly(const GlyphAssemblyData&);
76
    void setGlyphAssembly(const GlyphAssemblyData&);
Lines 80-86 public: a/Source/WebCore/rendering/mathml/MathOperator.h_sec3
80
    void paintHorizontalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&);
85
    void paintHorizontalGlyphAssembly(const RenderStyle&, PaintInfo&, const LayoutPoint&);
81
86
82
    UChar m_baseCharacter;
87
    UChar m_baseCharacter;
83
    bool m_isVertical;
88
    OperatorType m_operatorType;
84
    StretchType m_stretchType;
89
    StretchType m_stretchType;
85
    union {
90
    union {
86
        GlyphData m_variant;
91
        GlyphData m_variant;
- a/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp -3 / +12 lines
Lines 267-273 void RenderMathMLOperator::computePreferredLogicalWidths() a/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp_sec1
267
        return;
267
        return;
268
    }
268
    }
269
269
270
    m_mathOperator.setOperator(m_textContent, m_isVertical);
270
    MathOperator::OperatorType type;
271
    if (isLargeOperatorInDisplayStyle())
272
        type = MathOperator::OperatorType::DisplayOperator;
273
    else
274
        type = m_isVertical ? MathOperator::OperatorType::VerticalOperator : MathOperator::OperatorType::HorizontalOperator;
275
    m_mathOperator.setOperator(m_textContent, type);
271
    GlyphData baseGlyph;
276
    GlyphData baseGlyph;
272
    float maximumGlyphWidth = m_mathOperator.getBaseGlyph(style(), baseGlyph) ? advanceWidthForGlyph(baseGlyph) : 0;
277
    float maximumGlyphWidth = m_mathOperator.getBaseGlyph(style(), baseGlyph) ? advanceWidthForGlyph(baseGlyph) : 0;
273
    if (!m_isVertical) {
278
    if (!m_isVertical) {
Lines 369-375 void RenderMathMLOperator::updateStyle() a/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp_sec2
369
    if (!shouldAllowStretching())
374
    if (!shouldAllowStretching())
370
        return;
375
        return;
371
376
372
    m_mathOperator.setOperator(m_textContent, m_isVertical);
377
    MathOperator::OperatorType type;
378
    if (isLargeOperatorInDisplayStyle())
379
        type = MathOperator::OperatorType::DisplayOperator;
380
    else
381
        type = m_isVertical ? MathOperator::OperatorType::VerticalOperator : MathOperator::OperatorType::HorizontalOperator;
382
    m_mathOperator.setOperator(m_textContent, type);
373
    if (m_isVertical && isLargeOperatorInDisplayStyle())
383
    if (m_isVertical && isLargeOperatorInDisplayStyle())
374
        m_mathOperator.calculateDisplayStyleLargeOperator(style());
384
        m_mathOperator.calculateDisplayStyleLargeOperator(style());
375
    else {
385
    else {
376
- 

Return to Bug 156950