Changeset 199978 in webkit


Ignore:
Timestamp:
Apr 25, 2016 12:04:46 AM (8 years ago)
Author:
fred.wang@free.fr
Message:

Minor refactoring in RenderMathMLOperator
https://bugs.webkit.org/show_bug.cgi?id=156906

Patch by Frederic Wang <fwang@igalia.com> on 2016-04-25
Reviewed by Martin Robinson.

No new tests, this is only minor refactoring that does not change the behavior.

  • rendering/mathml/RenderMathMLOperator.cpp:

(WebCore::RenderMathMLOperator::getGlyphAssemblyFallBack):
We rename the "state" integer to an "expected" enum indicating the next expected part.
(WebCore::RenderMathMLOperator::paintGlyph): We add a missing dot at the end of a sequence.
We also replace ceil(x+1) with ceil(x)+1 to get rid of the temporary variable.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r199976 r199978  
     12016-04-25  Frederic Wang  <fwang@igalia.com>
     2
     3        Minor refactoring in RenderMathMLOperator
     4        https://bugs.webkit.org/show_bug.cgi?id=156906
     5
     6        Reviewed by Martin Robinson.
     7
     8        No new tests, this is only minor refactoring that does not change the behavior.
     9
     10        * rendering/mathml/RenderMathMLOperator.cpp:
     11        (WebCore::RenderMathMLOperator::getGlyphAssemblyFallBack):
     12        We rename the "state" integer to an "expected" enum indicating the next expected part.
     13        (WebCore::RenderMathMLOperator::paintGlyph): We add a missing dot at the end of a sequence.
     14        We also replace ceil(x+1) with ceil(x)+1 to get rid of the temporary variable.
     15
    1162016-04-24  Chris Dumez  <cdumez@apple.com>
    217
  • trunk/Source/WebCore/rendering/mathml/RenderMathMLOperator.cpp

    r199964 r199978  
    407407        return false; // This is not supported: there are too many pieces.
    408408
    409     // We now browse the list of pieces.
    410     // 1 = look for a left/bottom glyph
    411     // 2 = look for an extender between left/bottom and mid
    412     // 4 = look for a middle glyph
    413     // 5 = look for an extender between middle and right/top
    414     // 5 = look for a right/top glyph
    415     // 6 = no more piece expected
    416     unsigned state = 1;
    417 
     409    // We now browse the list of pieces from left to right for horizontal operators and from bottom to top for vertical operators.
     410    enum PartType {
     411        Start,
     412        ExtenderBetweenStartAndMiddle,
     413        Middle,
     414        ExtenderBetweenMiddleAndEnd,
     415        End,
     416        None
     417    };
     418    PartType expectedPartType = Start;
    418419    extension.glyph = 0;
    419420    middle.glyph = 0;
    420421    for (auto& part : assemblyParts) {
    421         if ((state == 2 || state == 3) && nonExtenderCount < 3) {
    422             // We do not try to find a middle glyph.
    423             state += 2;
     422        if (nonExtenderCount < 3) {
     423            // If we only have at most two non-extenders then we skip the middle glyph.
     424            if (expectedPartType == ExtenderBetweenStartAndMiddle)
     425                expectedPartType = ExtenderBetweenMiddleAndEnd;
     426            else if (expectedPartType == Middle)
     427                expectedPartType = End;
    424428        }
    425429        if (part.isExtender) {
    426430            if (!extension.glyph)
    427                 extension.glyph = part.glyph;
     431                extension.glyph = part.glyph; // We copy the extender part.
    428432            else if (extension.glyph != part.glyph)
    429433                return false; // This is not supported: the assembly has different extenders.
    430434
    431             if (state == 1) {
    432                 // We ignore left/bottom piece and multiple successive extenders.
    433                 state = 2;
    434             } else if (state == 3) {
    435                 // We ignore middle piece and multiple successive extenders.
    436                 state = 4;
    437             } else if (state >= 5)
    438                 return false; // This is not supported: we got an unexpected extender.
    439             continue;
    440         }
    441 
    442         if (state == 1) {
     435            switch (expectedPartType) {
     436            case Start:
     437                // We ignore the left/bottom part.
     438                expectedPartType = ExtenderBetweenStartAndMiddle;
     439                continue;
     440            case Middle:
     441                // We ignore the middle part.
     442                expectedPartType = ExtenderBetweenMiddleAndEnd;
     443                continue;
     444            case End:
     445            case None:
     446                // This is not supported: we got an unexpected extender.
     447                return false;
     448            case ExtenderBetweenStartAndMiddle:
     449            case ExtenderBetweenMiddleAndEnd:
     450                // We ignore multiple consecutive extenders.
     451                continue;
     452            }
     453        }
     454
     455        switch (expectedPartType) {
     456        case Start:
    443457            // We copy the left/bottom part.
    444458            bottom.glyph = part.glyph;
    445             state = 2;
     459            expectedPartType = ExtenderBetweenStartAndMiddle;
    446460            continue;
    447         }
    448 
    449         if (state == 2 || state == 3) {
     461        case ExtenderBetweenStartAndMiddle:
     462        case Middle:
    450463            // We copy the middle part.
    451464            middle.glyph = part.glyph;
    452             state = 4;
     465            expectedPartType = ExtenderBetweenMiddleAndEnd;
    453466            continue;
    454         }
    455 
    456         if (state == 4 || state == 5) {
     467        case ExtenderBetweenMiddleAndEnd:
     468        case End:
    457469            // We copy the right/top part.
    458470            top.glyph = part.glyph;
    459             state = 6;
     471            expectedPartType = None;
     472            continue;
     473        case None:
     474            // This is not supported: we got an unexpected non-extender part.
     475            return false;
    460476        }
    461477    }
     
    709725    // In order to have glyphs fit snugly with one another we snap the connecting edges to pixel boundaries
    710726    // and trim off one pixel. The pixel trim is to account for fonts that have edge pixels that have less
    711     // than full coverage. These edge pixels can introduce small seams between connected glyphs
     727    // than full coverage. These edge pixels can introduce small seams between connected glyphs.
    712728    FloatRect clipBounds = info.rect;
    713729    switch (trim) {
     
    720736        clipBounds.shiftMaxYEdgeTo(glyphPaintRect.maxY());
    721737        break;
    722     case TrimTopAndBottom: {
    723         LayoutUnit temp = glyphPaintRect.y() + 1;
    724         glyphPaintRect.shiftYEdgeTo(temp.ceil());
     738    case TrimTopAndBottom:
     739        glyphPaintRect.shiftYEdgeTo(glyphPaintRect.y().ceil() + 1);
    725740        glyphPaintRect.shiftMaxYEdgeTo(glyphPaintRect.maxY().floor() - 1);
    726741        clipBounds.shiftYEdgeTo(glyphPaintRect.y());
    727742        clipBounds.shiftMaxYEdgeTo(glyphPaintRect.maxY());
    728     }
    729743        break;
    730744    case TrimLeft:
     
    736750        clipBounds.shiftMaxXEdgeTo(glyphPaintRect.maxX());
    737751        break;
    738     case TrimLeftAndRight: {
    739         LayoutUnit temp = glyphPaintRect.x() + 1;
    740         glyphPaintRect.shiftXEdgeTo(temp.ceil());
     752    case TrimLeftAndRight:
     753        glyphPaintRect.shiftXEdgeTo(glyphPaintRect.x().ceil() + 1);
    741754        glyphPaintRect.shiftMaxXEdgeTo(glyphPaintRect.maxX().floor() - 1);
    742755        clipBounds.shiftXEdgeTo(glyphPaintRect.x());
    743756        clipBounds.shiftMaxXEdgeTo(glyphPaintRect.maxX());
    744     }
    745757    }
    746758
Note: See TracChangeset for help on using the changeset viewer.