示例#1
0
// static
void TextPainter::updateGraphicsContext(GraphicsContext& context,
                                        const Style& textStyle,
                                        bool horizontal,
                                        GraphicsContextStateSaver& stateSaver) {
  TextDrawingModeFlags mode = context.textDrawingMode();
  if (textStyle.strokeWidth > 0) {
    TextDrawingModeFlags newMode = mode | TextModeStroke;
    if (mode != newMode) {
      if (!stateSaver.saved())
        stateSaver.save();
      context.setTextDrawingMode(newMode);
      mode = newMode;
    }
  }

  if (mode & TextModeFill && textStyle.fillColor != context.fillColor())
    context.setFillColor(textStyle.fillColor);

  if (mode & TextModeStroke) {
    if (textStyle.strokeColor != context.strokeColor())
      context.setStrokeColor(textStyle.strokeColor);
    if (textStyle.strokeWidth != context.strokeThickness())
      context.setStrokeThickness(textStyle.strokeWidth);
  }

  if (textStyle.shadow) {
    if (!stateSaver.saved())
      stateSaver.save();
    context.setDrawLooper(textStyle.shadow->createDrawLooper(
        DrawLooperBuilder::ShadowIgnoresAlpha, textStyle.currentColor,
        horizontal));
  }
}
// static
void TextPainter::updateGraphicsContext(GraphicsContext* context, const Style& textStyle, bool horizontal, GraphicsContextStateSaver& stateSaver)
{
    TextDrawingModeFlags mode = context->textDrawingMode();
    if (textStyle.strokeWidth > 0) {
        TextDrawingModeFlags newMode = mode | TextModeStroke;
        if (mode != newMode) {
            if (!stateSaver.saved())
                stateSaver.save();
            context->setTextDrawingMode(newMode);
            mode = newMode;
        }
    }

    if (mode & TextModeFill && textStyle.fillColor != context->fillColor())
        context->setFillColor(textStyle.fillColor);

    if (mode & TextModeStroke) {
        if (textStyle.strokeColor != context->strokeColor())
            context->setStrokeColor(textStyle.strokeColor);
        if (textStyle.strokeWidth != context->strokeThickness())
            context->setStrokeThickness(textStyle.strokeWidth);
    }

    // Text shadows are disabled when printing. http://crbug.com/258321
    if (textStyle.shadow && !context->printing()) {
        if (!stateSaver.saved())
            stateSaver.save();
        context->setDrawLooper(textStyle.shadow->createDrawLooper(DrawLooperBuilder::ShadowIgnoresAlpha, textStyle.currentColor, horizontal));
    }
}
static bool setupNonScalingStrokeContext(AffineTransform& strokeTransform, GraphicsContextStateSaver& stateSaver)
{
    if (!strokeTransform.isInvertible())
        return false;

    stateSaver.save();
    stateSaver.context().concatCTM(strokeTransform.inverse());
    return true;
}
示例#4
0
bool RenderSVGShape::setupNonScalingStrokeContext(AffineTransform& strokeTransform, GraphicsContextStateSaver& stateSaver)
{
    Optional<AffineTransform> inverse = strokeTransform.inverse();
    if (!inverse)
        return false;

    stateSaver.save();
    stateSaver.context()->concatCTM(inverse.value());
    return true;
}
bool SVGLayoutSupport::updateGraphicsContext(const PaintInfo& paintInfo, GraphicsContextStateSaver& stateSaver, const ComputedStyle& style, LayoutObject& layoutObject, LayoutSVGResourceMode resourceMode, const AffineTransform* additionalPaintServerTransform)
{
    ASSERT(paintInfo.context == stateSaver.context());

    GraphicsContext& context = *paintInfo.context;
    if (paintInfo.isRenderingClipPathAsMaskImage()) {
        if (resourceMode == ApplyToStrokeMode)
            return false;
        context.setFillColor(SVGComputedStyle::initialFillPaintColor());
        return true;
    }

    SVGPaintServer paintServer = SVGPaintServer::requestForLayoutObject(layoutObject, style, resourceMode);
    if (!paintServer.isValid())
        return false;

    if (additionalPaintServerTransform && paintServer.isTransformDependent())
        paintServer.prependTransform(*additionalPaintServerTransform);

    const SVGComputedStyle& svgStyle = style.svgStyle();
    float paintAlpha = resourceMode == ApplyToFillMode ? svgStyle.fillOpacity() : svgStyle.strokeOpacity();
    paintServer.apply(context, resourceMode, paintAlpha, stateSaver);

    if (resourceMode == ApplyToFillMode)
        context.setFillRule(svgStyle.fillRule());
    else
        applyStrokeStyleToContext(context, style, layoutObject);

    return true;
}
示例#6
0
bool SVGRenderSupport::updateGraphicsContext(const PaintInfo& paintInfo, GraphicsContextStateSaver& stateSaver, RenderStyle* style, RenderObject& renderer, RenderSVGResourceMode resourceMode, const AffineTransform* additionalPaintServerTransform)
{
    ASSERT(style);
    ASSERT(paintInfo.context == stateSaver.context());

    GraphicsContext* context = paintInfo.context;
    if (paintInfo.isRenderingClipPathAsMaskImage()) {
        if (resourceMode == ApplyToStrokeMode)
            return false;
        context->setAlphaAsFloat(1);
        context->setFillColor(SVGRenderStyle::initialFillPaintColor());
        return true;
    }

    SVGPaintServer paintServer = SVGPaintServer::requestForRenderer(renderer, style, resourceMode);
    if (!paintServer.isValid())
        return false;

    if (additionalPaintServerTransform && paintServer.isTransformDependent())
        paintServer.prependTransform(*additionalPaintServerTransform);

    paintServer.apply(*context, resourceMode, &stateSaver);

    const SVGRenderStyle& svgStyle = style->svgStyle();

    if (resourceMode == ApplyToFillMode) {
        context->setAlphaAsFloat(svgStyle.fillOpacity());
        context->setFillRule(svgStyle.fillRule());
    } else {
        context->setAlphaAsFloat(svgStyle.strokeOpacity());
        applyStrokeStyleToContext(context, style, &renderer);
    }
    return true;
}