Пример #1
0
Gradient* CSSGradientValue::createGradient(RenderObject* renderer, const IntSize& size)
{
    ASSERT(!size.isEmpty());
    
    float zoomFactor = renderer->style()->effectiveZoom();
    
    FloatPoint firstPoint = resolvePoint(m_firstX.get(), m_firstY.get(), size, zoomFactor);
    FloatPoint secondPoint = resolvePoint(m_secondX.get(), m_secondY.get(), size, zoomFactor);
    
    Gradient* gradient = 0;
    if (m_type == CSSLinearGradient)
        gradient = new Gradient(firstPoint, secondPoint);
    else {
        float firstRadius = resolveRadius(m_firstRadius.get(), zoomFactor);
        float secondRadius = resolveRadius(m_secondRadius.get(), zoomFactor);
        gradient = new Gradient(firstPoint, firstRadius, secondPoint, secondRadius);
    }

    // Now add the stops.
    sortStopsIfNeeded();

    // We have to resolve colors.
    for (unsigned i = 0; i < m_stops.size(); i++) {
        Color color = renderer->document()->styleSelector()->getColorFromPrimitiveValue(m_stops[i].m_color.get());
        gradient->addColorStop(m_stops[i].m_stop, color);
    }

    // The back end already sorted the stops.
    gradient->setStopsSorted(true);

    return gradient;
}
Пример #2
0
void LayoutSVGResourceGradient::addStops(
    Gradient& gradient,
    const Vector<Gradient::ColorStop>& stops) const {
  for (const auto& stop : stops)
    gradient.addColorStop(stop);
}