Esempio n. 1
0
void TrailingObjects::updateMidpointsForTrailingObjects(LineMidpointState& lineMidpointState, const InlineIterator& lBreak, CollapseFirstSpaceOrNot collapseFirstSpace)
{
    if (!m_whitespace)
        return;

    // This object is either going to be part of the last midpoint, or it is going to be the actual endpoint.
    // In both cases we just decrease our pos by 1 level to exclude the space, allowing it to - in effect - collapse into the newline.
    if (lineMidpointState.numMidpoints() % 2) {
        // Find the trailing space object's midpoint.
        int trailingSpaceMidpoint = lineMidpointState.numMidpoints() - 1;
        for ( ; trailingSpaceMidpoint > 0 && lineMidpointState.midpoints()[trailingSpaceMidpoint].object() != m_whitespace; --trailingSpaceMidpoint) { }
        ASSERT(trailingSpaceMidpoint >= 0);
        if (collapseFirstSpace == CollapseFirstSpace)
            lineMidpointState.midpoints()[trailingSpaceMidpoint].setOffset(lineMidpointState.midpoints()[trailingSpaceMidpoint].offset() -1);

        // Now make sure every single trailingPositionedBox following the trailingSpaceMidpoint properly stops and starts
        // ignoring spaces.
        size_t currentMidpoint = trailingSpaceMidpoint + 1;
        for (size_t i = 0; i < m_objects.size(); ++i) {
            if (currentMidpoint >= lineMidpointState.numMidpoints()) {
                // We don't have a midpoint for this box yet.
                lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_objects[i]);
            } else {
                ASSERT(lineMidpointState.midpoints()[currentMidpoint].object() == m_objects[i]);
                ASSERT(lineMidpointState.midpoints()[currentMidpoint + 1].object() == m_objects[i]);
            }
            currentMidpoint += 2;
        }
    } else if (!lBreak.object()) {
        ASSERT(m_whitespace->isText());
        ASSERT(collapseFirstSpace == CollapseFirstSpace);
        // Add a new end midpoint that stops right at the very end.
        unsigned length = m_whitespace->textLength();
        unsigned pos = length >= 2 ? length - 2 : UINT_MAX;
        InlineIterator endMid(0, m_whitespace, pos);
        lineMidpointState.startIgnoringSpaces(endMid);
        for (size_t i = 0; i < m_objects.size(); ++i) {
            lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_objects[i]);
        }
    }
}
Esempio n. 2
0
LineSegmentRange::LineSegmentRange(const InlineIterator& start, const InlineIterator& end)
    : start(start.root(), start.object(), start.offset())
    , end(end.root(), end.object(), end.offset())
    {
    }