⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphicscontextskia.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    platformContext()->canvas()->drawRect(r, paint);}void GraphicsContext::fillRoundedRect(const IntRect& rect,                                      const IntSize& topLeft,                                      const IntSize& topRight,                                      const IntSize& bottomLeft,                                      const IntSize& bottomRight,                                      const Color& color){    if (paintingDisabled())        return;    SkRect r = rect;    if (!isRectSkiaSafe(getCTM(), r))        // See fillRect().        ClipRectToCanvas(*platformContext()->canvas(), r, &r);    if (topLeft.width() + topRight.width() > rect.width()            || bottomLeft.width() + bottomRight.width() > rect.width()            || topLeft.height() + bottomLeft.height() > rect.height()            || topRight.height() + bottomRight.height() > rect.height()) {        // Not all the radii fit, return a rect. This matches the behavior of        // Path::createRoundedRectangle. Without this we attempt to draw a round        // shadow for a square box.        fillRect(rect, color);        return;    }    SkPath path;    addCornerArc(&path, r, topRight, 270);    addCornerArc(&path, r, bottomRight, 0);    addCornerArc(&path, r, bottomLeft, 90);    addCornerArc(&path, r, topLeft, 180);    SkPaint paint;    platformContext()->setupPaintForFilling(&paint);    platformContext()->canvas()->drawPath(path, paint);}TransformationMatrix GraphicsContext::getCTM() const{    const SkMatrix& m = platformContext()->canvas()->getTotalMatrix();    return TransformationMatrix(SkScalarToDouble(m.getScaleX()),      // a                                SkScalarToDouble(m.getSkewY()),       // b                                SkScalarToDouble(m.getSkewX()),       // c                                SkScalarToDouble(m.getScaleY()),      // d                                SkScalarToDouble(m.getTranslateX()),  // e                                SkScalarToDouble(m.getTranslateY())); // f}FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& rect){    // This logic is copied from GraphicsContextCG, eseidel 5/05/08    // It is not enough just to round to pixels in device space. The rotation    // part of the affine transform matrix to device space can mess with this    // conversion if we have a rotating image like the hands of the world clock    // widget. We just need the scale, so we get the affine transform matrix and    // extract the scale.    const SkMatrix& deviceMatrix = platformContext()->canvas()->getTotalMatrix();    if (deviceMatrix.isIdentity())        return rect;    float deviceScaleX = sqrtf(square(deviceMatrix.getScaleX())        + square(deviceMatrix.getSkewY()));    float deviceScaleY = sqrtf(square(deviceMatrix.getSkewX())        + square(deviceMatrix.getScaleY()));    FloatPoint deviceOrigin(rect.x() * deviceScaleX, rect.y() * deviceScaleY);    FloatPoint deviceLowerRight((rect.x() + rect.width()) * deviceScaleX,        (rect.y() + rect.height()) * deviceScaleY);    deviceOrigin.setX(roundf(deviceOrigin.x()));    deviceOrigin.setY(roundf(deviceOrigin.y()));    deviceLowerRight.setX(roundf(deviceLowerRight.x()));    deviceLowerRight.setY(roundf(deviceLowerRight.y()));    // Don't let the height or width round to 0 unless either was originally 0    if (deviceOrigin.y() == deviceLowerRight.y() && rect.height() != 0)        deviceLowerRight.move(0, 1);    if (deviceOrigin.x() == deviceLowerRight.x() && rect.width() != 0)        deviceLowerRight.move(1, 0);    FloatPoint roundedOrigin(deviceOrigin.x() / deviceScaleX,        deviceOrigin.y() / deviceScaleY);    FloatPoint roundedLowerRight(deviceLowerRight.x() / deviceScaleX,        deviceLowerRight.y() / deviceScaleY);    return FloatRect(roundedOrigin, roundedLowerRight - roundedOrigin);}void GraphicsContext::scale(const FloatSize& size){    if (paintingDisabled())        return;    platformContext()->canvas()->scale(WebCoreFloatToSkScalar(size.width()),        WebCoreFloatToSkScalar(size.height()));}void GraphicsContext::setAlpha(float alpha){    if (paintingDisabled())        return;    platformContext()->setAlpha(alpha);}void GraphicsContext::setCompositeOperation(CompositeOperator op){    if (paintingDisabled())        return;    platformContext()->setPorterDuffMode(WebCoreCompositeToSkiaComposite(op));}void GraphicsContext::setImageInterpolationQuality(InterpolationQuality){    notImplemented();}void GraphicsContext::setLineCap(LineCap cap){    if (paintingDisabled())        return;    switch (cap) {    case ButtCap:        platformContext()->setLineCap(SkPaint::kButt_Cap);        break;    case RoundCap:        platformContext()->setLineCap(SkPaint::kRound_Cap);        break;    case SquareCap:        platformContext()->setLineCap(SkPaint::kSquare_Cap);        break;    default:        ASSERT(0);        break;    }}void GraphicsContext::setLineDash(const DashArray& dashes, float dashOffset){    if (paintingDisabled())        return;    // FIXME: This is lifted directly off SkiaSupport, lines 49-74    // so it is not guaranteed to work correctly.    size_t dashLength = dashes.size();    if (!dashLength)        return;    size_t count = (dashLength % 2) == 0 ? dashLength : dashLength * 2;    SkScalar* intervals = new SkScalar[count];    for (unsigned int i = 0; i < count; i++)        intervals[i] = dashes[i % dashLength];    platformContext()->setDashPathEffect(new SkDashPathEffect(intervals, count, dashOffset));    delete[] intervals;}void GraphicsContext::setLineJoin(LineJoin join){    if (paintingDisabled())        return;    switch (join) {    case MiterJoin:        platformContext()->setLineJoin(SkPaint::kMiter_Join);        break;    case RoundJoin:        platformContext()->setLineJoin(SkPaint::kRound_Join);        break;    case BevelJoin:        platformContext()->setLineJoin(SkPaint::kBevel_Join);        break;    default:        ASSERT(0);        break;    }}void GraphicsContext::setMiterLimit(float limit){    if (paintingDisabled())        return;    platformContext()->setMiterLimit(limit);}void GraphicsContext::setPlatformFillColor(const Color& color){    if (paintingDisabled())        return;    platformContext()->setFillColor(color.rgb());}void GraphicsContext::setPlatformShadow(const IntSize& size,                                        int blurInt,                                        const Color& color){    if (paintingDisabled())        return;    double width = size.width();    double height = size.height();    double blur = blurInt;    // TODO(tc): This still does not address the issue that shadows    // within canvas elements should ignore transforms.    if (m_common->state.shadowsIgnoreTransforms)  {        // Currently only the GraphicsContext associated with the        // CanvasRenderingContext for HTMLCanvasElement have shadows ignore        // Transforms. So with this flag set, we know this state is associated        // with a CanvasRenderingContext.        // CG uses natural orientation for Y axis, but the HTML5 canvas spec        // does not.        // So we now flip the height since it was flipped in        // CanvasRenderingContext in order to work with CG.        height = -height;    }    SkColor c;    if (color.isValid())        c = color.rgb();    else        c = SkColorSetARGB(0xFF/3, 0, 0, 0);    // "std" apple shadow color.    // TODO(tc): Should we have a max value for the blur?  CG clamps at 1000.0    // for perf reasons.    SkDrawLooper* dl = new SkBlurDrawLooper(blur / 2, width, height, c);    platformContext()->setDrawLooper(dl);    dl->unref();}void GraphicsContext::setPlatformStrokeColor(const Color& strokecolor){    if (paintingDisabled())        return;    platformContext()->setStrokeColor(strokecolor.rgb());}void GraphicsContext::setPlatformStrokeStyle(const StrokeStyle& stroke){    if (paintingDisabled())        return;    platformContext()->setStrokeStyle(stroke);}void GraphicsContext::setPlatformStrokeThickness(float thickness){    if (paintingDisabled())        return;    platformContext()->setStrokeThickness(thickness);}void GraphicsContext::setPlatformTextDrawingMode(int mode){    if (paintingDisabled())        return;    platformContext()->setTextDrawingMode(mode);}void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect){}void GraphicsContext::setPlatformShouldAntialias(bool enable){    if (paintingDisabled())        return;    platformContext()->setUseAntialiasing(enable);}void GraphicsContext::strokeArc(const IntRect& r, int startAngle, int angleSpan){    if (paintingDisabled())        return;    SkPaint paint;    SkRect oval = r;    if (strokeStyle() == NoStroke) {        // Stroke using the fill color.        // TODO(brettw) is this really correct? It seems unreasonable.        platformContext()->setupPaintForFilling(&paint);        paint.setStyle(SkPaint::kStroke_Style);        paint.setStrokeWidth(WebCoreFloatToSkScalar(strokeThickness()));    } else        platformContext()->setupPaintForStroking(&paint, 0, 0);    // We do this before converting to scalar, so we don't overflow SkFixed.    startAngle = fastMod(startAngle, 360);    angleSpan = fastMod(angleSpan, 360);    SkPath path;    path.addArc(oval, SkIntToScalar(-startAngle), SkIntToScalar(-angleSpan));    if (!isPathSkiaSafe(getCTM(), path))        return;    platformContext()->canvas()->drawPath(path, paint);}void GraphicsContext::strokePath(){    if (paintingDisabled())        return;    SkPath path = platformContext()->currentPathInLocalCoordinates();    if (!isPathSkiaSafe(getCTM(), path))        return;    const GraphicsContextState& state = m_common->state;    ColorSpace colorSpace = state.strokeColorSpace;    if (colorSpace == SolidColorSpace && !strokeColor().alpha())        return;    SkPaint paint;    platformContext()->setupPaintForStroking(&paint, 0, 0);    if (colorSpace == PatternColorSpace) {        SkShader* pat = state.strokePattern->createPlatformPattern(getCTM());        paint.setShader(pat);        pat->unref();    } else if (colorSpace == GradientColorSpace)        paint.setShader(state.strokeGradient->platformGradient());    platformContext()->canvas()->drawPath(path, paint);}void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth){    if (paintingDisabled())        return;    if (!isRectSkiaSafe(getCTM(), rect))        return;    const GraphicsContextState& state = m_common->state;    ColorSpace colorSpace = state.strokeColorSpace;    if (colorSpace == SolidColorSpace && !strokeColor().alpha())        return;    SkPaint paint;    platformContext()->setupPaintForStroking(&paint, 0, 0);    paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth));    if (colorSpace == PatternColorSpace) {        SkShader* pat = state.strokePattern->createPlatformPattern(getCTM());        paint.setShader(pat);        pat->unref();    } else if (colorSpace == GradientColorSpace)        paint.setShader(state.strokeGradient->platformGradient());    platformContext()->canvas()->drawRect(rect, paint);}void GraphicsContext::rotate(float angleInRadians){    if (paintingDisabled())        return;    platformContext()->canvas()->rotate(WebCoreFloatToSkScalar(        angleInRadians * (180.0f / 3.14159265f)));}void GraphicsContext::translate(float w, float h){    if (paintingDisabled())        return;    platformContext()->canvas()->translate(WebCoreFloatToSkScalar(w),                                           WebCoreFloatToSkScalar(h));}}  // namespace WebCore

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -