示例#1
0
SVGPaintServer LayoutSVGResourceGradient::preparePaintServer(
    const LayoutObject& object) {
  clearInvalidationMask();

  // Be sure to synchronize all SVG properties on the gradientElement _before_
  // processing any further. Otherwhise the call to collectGradientAttributes()
  // in createTileImage(), may cause the SVG DOM property synchronization to
  // kick in, which causes removeAllClientsFromCache() to be called, which in
  // turn deletes our GradientData object! Leaving out the line below will cause
  // svg/dynamic-updates/SVG*GradientElement-svgdom* to crash.
  SVGGradientElement* gradientElement = toSVGGradientElement(element());
  if (!gradientElement)
    return SVGPaintServer::invalid();

  if (m_shouldCollectGradientAttributes) {
    gradientElement->synchronizeAnimatedSVGAttribute(anyQName());
    if (!collectGradientAttributes(gradientElement))
      return SVGPaintServer::invalid();

    m_shouldCollectGradientAttributes = false;
  }

  // Spec: When the geometry of the applicable element has no width or height
  // and objectBoundingBox is specified, then the given effect (e.g. a gradient
  // or a filter) will be ignored.
  FloatRect objectBoundingBox = object.objectBoundingBox();
  if (gradientUnits() == SVGUnitTypes::kSvgUnitTypeObjectboundingbox &&
      objectBoundingBox.isEmpty())
    return SVGPaintServer::invalid();

  std::unique_ptr<GradientData>& gradientData =
      m_gradientMap.add(&object, nullptr).storedValue->value;
  if (!gradientData)
    gradientData = WTF::wrapUnique(new GradientData);

  // Create gradient object
  if (!gradientData->gradient) {
    gradientData->gradient = buildGradient();

    // We want the text bounding box applied to the gradient space transform
    // now, so the gradient shader can use it.
    if (gradientUnits() == SVGUnitTypes::kSvgUnitTypeObjectboundingbox &&
        !objectBoundingBox.isEmpty()) {
      gradientData->userspaceTransform.translate(objectBoundingBox.x(),
                                                 objectBoundingBox.y());
      gradientData->userspaceTransform.scaleNonUniform(
          objectBoundingBox.width(), objectBoundingBox.height());
    }

    AffineTransform gradientTransform = calculateGradientTransform();
    gradientData->userspaceTransform *= gradientTransform;
  }

  if (!gradientData->gradient)
    return SVGPaintServer::invalid();

  return SVGPaintServer(gradientData->gradient,
                        gradientData->userspaceTransform);
}
示例#2
0
/*! \todo split param update from graphic creation
*/
void gradientDialog::slotUpdate()
{
   QString s;
	QPalette palette;
	QBrush brush;
	gParam.direction=(270+dial->value())%360;
	gParam.pos1=pos1SpinBox->value();
	gParam.pos2=pos2SpinBox->value();
	gParam.pos3=pos3SpinBox->value();
	gParam.pos4=pos4SpinBox->value();

  if(noGradientButton->isChecked()) gParam.type=sgradientParam::NONE;
  else if (linearGradientButton->isChecked()) gParam.type=sgradientParam::LINEAR;
  else if (radialGradientButton->isChecked()) gParam.type=sgradientParam::RADIAL;
  else if (conicalGradientButton->isChecked()) gParam.type=sgradientParam::CONICAL;

  s=gParam.color1.name();
  color1Button->setStyleSheet("background-color: "+s+"; border-style: outset; border-width: 2px;border-radius: 10px; border-color: beige; padding: 6px");
  s=gParam.color2.name();
  color2Button->setStyleSheet("background-color: "+s+"; border-style: outset; border-width: 2px;border-radius: 10px; border-color: beige; padding: 6px");
  s=gParam.color3.name();
  color3Button->setStyleSheet("background-color: "+s+"; border-style: outset; border-width: 2px;border-radius: 10px; border-color: beige; padding: 6px");
  s=gParam.color4.name();
  color4Button->setStyleSheet("background-color: "+s+"; border-style: outset; border-width: 2px;border-radius: 10px; border-color: beige; padding: 6px");

//	brush.setStyle(Qt::SolidPattern);

//	brush.setColor(gParam.color1);
//	palette.setBrush(QPalette::Active, QPalette::Button, brush);
//	color1Button->setPalette(palette);

//	brush.setColor(gParam.color2);11
//	palette.setBrush(QPalette::Active, QPalette::Button, brush);
//	color2Button->setPalette(palette);
//	brush.setColor(gParam.color3);
//	palette.setBrush(QPalette::Active, QPalette::Button, brush);
//	color3Button->setPalette(palette);
//	brush.setColor(gParam.color4);
//	palette.setBrush(QPalette::Active, QPalette::Button, brush);
//	color4Button->setPalette(palette);
	brush.setStyle(Qt::SolidPattern);
	if(gParam.type!=sgradientParam::NONE)
		{
			QBrush br(buildGradient(gParam,previewLabel->rect()));
			palette.setBrush(QPalette::Active, QPalette::Base, br);
		}
	else
		{
			QBrush br(gParam.color1);
			palette.setBrush(QPalette::Active, QPalette::Base, br);
		}
	previewLabel->setPalette(palette);
}
bool RenderSVGResourceGradient::applyResource(RenderObject* object, RenderStyle* style, GraphicsContext*& context, unsigned short resourceMode)
{
    ASSERT(object);
    ASSERT(style);
    ASSERT(context);
    ASSERT(resourceMode != ApplyToDefaultMode);

    // Be sure to synchronize all SVG properties on the gradientElement _before_ processing any further.
    // Otherwhise the call to collectGradientAttributes() in createTileImage(), may cause the SVG DOM property
    // synchronization to kick in, which causes removeAllClientsFromCache() to be called, which in turn deletes our
    // GradientData object! Leaving out the line below will cause svg/dynamic-updates/SVG*GradientElement-svgdom* to crash.
    SVGGradientElement* gradientElement = static_cast<SVGGradientElement*>(node());
    if (!gradientElement)
        return false;

    if (m_shouldCollectGradientAttributes) {
        gradientElement->synchronizeAnimatedSVGAttribute(anyQName());
        if (!collectGradientAttributes(gradientElement))
            return false;

        m_shouldCollectGradientAttributes = false;
    }

    // Spec: When the geometry of the applicable element has no width or height and objectBoundingBox is specified,
    // then the given effect (e.g. a gradient or a filter) will be ignored.
    FloatRect objectBoundingBox = object->objectBoundingBox();
    if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && objectBoundingBox.isEmpty())
        return false;

    OwnPtr<GradientData>& gradientData = m_gradientMap.add(object, nullptr).iterator->value;
    if (!gradientData)
        gradientData = adoptPtr(new GradientData);

    bool isPaintingText = resourceMode & ApplyToTextMode;

    // Create gradient object
    if (!gradientData->gradient) {
        buildGradient(gradientData.get());

        // CG platforms will handle the gradient space transform for text after applying the
        // resource, so don't apply it here. For non-CG platforms, we want the text bounding
        // box applied to the gradient space transform now, so the gradient shader can use it.
#if USE(CG)
        if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty() && !isPaintingText) {
#else
        if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty()) {
#endif
            gradientData->userspaceTransform.translate(objectBoundingBox.x(), objectBoundingBox.y());
            gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
        }

        AffineTransform gradientTransform;
        calculateGradientTransform(gradientTransform);

        gradientData->userspaceTransform *= gradientTransform;
        if (isPaintingText) {
            // Depending on font scaling factor, we may need to rescale the gradient here since
            // text painting removes the scale factor from the context.
            AffineTransform additionalTextTransform;
            if (shouldTransformOnTextPainting(object, additionalTextTransform))
                gradientData->userspaceTransform *= additionalTextTransform;
        }
        gradientData->gradient->setGradientSpaceTransform(gradientData->userspaceTransform);
    }

    if (!gradientData->gradient)
        return false;

    // Draw gradient
    context->save();

    if (isPaintingText) {
#if USE(CG)
        if (!createMaskAndSwapContextForTextGradient(context, m_savedContext, m_imageBuffer, object)) {
            context->restore();
            return false;
        }
#endif

        context->setTextDrawingMode(resourceMode & ApplyToFillMode ? TextModeFill : TextModeStroke);
    }

    const SVGRenderStyle* svgStyle = style->svgStyle();
    ASSERT(svgStyle);

    if (resourceMode & ApplyToFillMode) {
        context->setAlpha(svgStyle->fillOpacity());
        context->setFillGradient(gradientData->gradient);
        context->setFillRule(svgStyle->fillRule());
    } else if (resourceMode & ApplyToStrokeMode) {
        if (svgStyle->vectorEffect() == VE_NON_SCALING_STROKE)
            gradientData->gradient->setGradientSpaceTransform(transformOnNonScalingStroke(object, gradientData->userspaceTransform));
        context->setAlpha(svgStyle->strokeOpacity());
        context->setStrokeGradient(gradientData->gradient);
        SVGRenderSupport::applyStrokeStyleToContext(context, style, object);
    }

    return true;
}

void RenderSVGResourceGradient::postApplyResource(RenderObject* object, GraphicsContext*& context, unsigned short resourceMode, const Path* path, const RenderSVGShape* shape)
{
    ASSERT(context);
    ASSERT(resourceMode != ApplyToDefaultMode);

    if (resourceMode & ApplyToTextMode) {
#if USE(CG)
        // CG requires special handling for gradient on text
        GradientData* gradientData;
        if (m_savedContext && (gradientData = m_gradientMap.get(object))) {
            // Restore on-screen drawing context
            context = m_savedContext;
            m_savedContext = 0;

            AffineTransform gradientTransform;
            calculateGradientTransform(gradientTransform);

            FloatRect targetRect;
            gradientData->gradient->setGradientSpaceTransform(clipToTextMask(context, m_imageBuffer, targetRect, object, gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX, gradientTransform));
            context->setFillGradient(gradientData->gradient);

            context->fillRect(targetRect);
            m_imageBuffer.clear();
        }
#else
        UNUSED_PARAM(object);
#endif
    } else {
        if (resourceMode & ApplyToFillMode) {
            if (path)
                context->fillPath(*path);
            else if (shape)
                shape->fillShape(context);
        }
        if (resourceMode & ApplyToStrokeMode) {
            if (path)
                context->strokePath(*path);
            else if (shape)
                shape->strokeShape(context);
        }
    }

    context->restore();
}
bool RenderSVGResourceGradient::applyResource(RenderObject* object, RenderStyle* style, GraphicsContext*& context, unsigned short resourceMode)
{
    ASSERT(object);
    ASSERT(style);
    ASSERT(context);
    ASSERT(resourceMode != ApplyToDefaultMode);

    clearInvalidationMask();

    // Be sure to synchronize all SVG properties on the gradientElement _before_ processing any further.
    // Otherwhise the call to collectGradientAttributes() in createTileImage(), may cause the SVG DOM property
    // synchronization to kick in, which causes removeAllClientsFromCache() to be called, which in turn deletes our
    // GradientData object! Leaving out the line below will cause svg/dynamic-updates/SVG*GradientElement-svgdom* to crash.
    SVGGradientElement* gradientElement = toSVGGradientElement(element());
    if (!gradientElement)
        return false;

    if (m_shouldCollectGradientAttributes) {
        gradientElement->synchronizeAnimatedSVGAttribute(anyQName());
        if (!collectGradientAttributes(gradientElement))
            return false;

        m_shouldCollectGradientAttributes = false;
    }

    // Spec: When the geometry of the applicable element has no width or height and objectBoundingBox is specified,
    // then the given effect (e.g. a gradient or a filter) will be ignored.
    FloatRect objectBoundingBox = object->objectBoundingBox();
    if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && objectBoundingBox.isEmpty())
        return false;

    OwnPtr<GradientData>& gradientData = m_gradientMap.add(object, nullptr).storedValue->value;
    if (!gradientData)
        gradientData = adoptPtr(new GradientData);

    // Create gradient object
    if (!gradientData->gradient) {
        buildGradient(gradientData.get());

        // We want the text bounding box applied to the gradient space transform now, so the gradient shader can use it.
        if (gradientUnits() == SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX && !objectBoundingBox.isEmpty()) {
            gradientData->userspaceTransform.translate(objectBoundingBox.x(), objectBoundingBox.y());
            gradientData->userspaceTransform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
        }

        AffineTransform gradientTransform;
        calculateGradientTransform(gradientTransform);

        gradientData->userspaceTransform *= gradientTransform;
    }

    if (!gradientData->gradient)
        return false;

    const SVGRenderStyle* svgStyle = style->svgStyle();
    ASSERT(svgStyle);

    AffineTransform computedGradientSpaceTransform = computeResourceSpaceTransform(object, gradientData->userspaceTransform, svgStyle, resourceMode);
    gradientData->gradient->setGradientSpaceTransform(computedGradientSpaceTransform);

    // Draw gradient
    context->save();

    if (resourceMode & ApplyToTextMode)
        context->setTextDrawingMode(resourceMode & ApplyToFillMode ? TextModeFill : TextModeStroke);

    if (resourceMode & ApplyToFillMode) {
        context->setAlphaAsFloat(svgStyle->fillOpacity());
        context->setFillGradient(gradientData->gradient);
        context->setFillRule(svgStyle->fillRule());
    } else if (resourceMode & ApplyToStrokeMode) {
        context->setAlphaAsFloat(svgStyle->strokeOpacity());
        context->setStrokeGradient(gradientData->gradient);
        SVGRenderSupport::applyStrokeStyleToContext(context, style, object);
    }

    return true;
}
bool RenderSVGResourceGradient::applyResource(RenderObject* object, RenderStyle* style, GraphicsContext*& context, unsigned short resourceMode)
{
    ASSERT(object);
    ASSERT(style);
    ASSERT(context);
    ASSERT(resourceMode != ApplyToDefaultMode);

    // Be sure to synchronize all SVG properties on the gradientElement _before_ processing any further.
    // Otherwhise the call to collectGradientAttributes() in createTileImage(), may cause the SVG DOM property
    // synchronization to kick in, which causes invalidateClients() to be called, which in turn deletes our
    // GradientData object! Leaving out the line below will cause svg/dynamic-updates/SVG*GradientElement-svgdom* to crash.
    SVGGradientElement* gradientElement = static_cast<SVGGradientElement*>(node());
    if (!gradientElement)
        return false;

    gradientElement->updateAnimatedSVGAttribute(anyQName());

    if (!m_gradient.contains(object))
        m_gradient.set(object, new GradientData);

    GradientData* gradientData = m_gradient.get(object);

    // Create gradient object
    if (!gradientData->gradient)
        buildGradient(gradientData, gradientElement);

    if (!gradientData->gradient)
        return false;

    // Draw gradient
    context->save();

    bool isPaintingText = resourceMode & ApplyToTextMode;
    if (isPaintingText) {
#if PLATFORM(CG)
        if (!createMaskAndSwapContextForTextGradient(context, m_savedContext, m_imageBuffer, object)) {
            context->restore();
            return false;
        }
#endif

        context->setTextDrawingMode(resourceMode & ApplyToFillMode ? cTextFill : cTextStroke);
    }

    AffineTransform transform;

    // CG platforms will handle the gradient space transform for text after applying the
    // resource, so don't apply it here. For non-CG platforms, we want the text bounding
    // box applied to the gradient space transform now, so the gradient shader can use it.
#if PLATFORM(CG)
    if (gradientData->boundingBoxMode && !isPaintingText) {
#else
    if (gradientData->boundingBoxMode) {
#endif
        FloatRect objectBoundingBox = object->objectBoundingBox();
        transform.translate(objectBoundingBox.x(), objectBoundingBox.y());
        transform.scaleNonUniform(objectBoundingBox.width(), objectBoundingBox.height());
    }

    transform.multiply(gradientData->transform);
    gradientData->gradient->setGradientSpaceTransform(transform);

    const SVGRenderStyle* svgStyle = style->svgStyle();
    ASSERT(svgStyle);

    if (resourceMode & ApplyToFillMode) {
        context->setAlpha(svgStyle->fillOpacity());
        context->setFillGradient(gradientData->gradient);
        context->setFillRule(svgStyle->fillRule());
    } else if (resourceMode & ApplyToStrokeMode) {
        context->setAlpha(svgStyle->strokeOpacity());
        context->setStrokeGradient(gradientData->gradient);
        applyStrokeStyleToContext(context, style, object);
    }

    return true;
}

void RenderSVGResourceGradient::postApplyResource(RenderObject* object, GraphicsContext*& context, unsigned short resourceMode)
{
    ASSERT(context);
    ASSERT(resourceMode != ApplyToDefaultMode);

    if (resourceMode & ApplyToTextMode) {
#if PLATFORM(CG)
        // CG requires special handling for gradient on text
        if (m_savedContext && m_gradient.contains(object)) {
            GradientData* gradientData = m_gradient.get(object);

            // Restore on-screen drawing context
            context = m_savedContext;
            m_savedContext = 0;

            gradientData->gradient->setGradientSpaceTransform(clipToTextMask(context, m_imageBuffer, object, gradientData));
            context->setFillGradient(gradientData->gradient);

            const RenderObject* textRootBlock = findTextRootObject(object);
            context->fillRect(textRootBlock->repaintRectInLocalCoordinates());

            m_imageBuffer.clear();
        }
#else
        UNUSED_PARAM(object);
#endif
    } else {
        if (resourceMode & ApplyToFillMode)
            context->fillPath();
        else if (resourceMode & ApplyToStrokeMode)
            context->strokePath();
    }

    context->restore();
}