void Path::addBeziersForRoundedRect(const FloatRect& rect, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius) { moveTo(FloatPoint(rect.x() + topLeftRadius.width(), rect.y())); addLineTo(FloatPoint(rect.maxX() - topRightRadius.width(), rect.y())); if (topRightRadius.width() > 0 || topRightRadius.height() > 0) addBezierCurveTo(FloatPoint(rect.maxX() - topRightRadius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.maxX(), rect.y() + topRightRadius.height() * gCircleControlPoint), FloatPoint(rect.maxX(), rect.y() + topRightRadius.height())); addLineTo(FloatPoint(rect.maxX(), rect.maxY() - bottomRightRadius.height())); if (bottomRightRadius.width() > 0 || bottomRightRadius.height() > 0) addBezierCurveTo(FloatPoint(rect.maxX(), rect.maxY() - bottomRightRadius.height() * gCircleControlPoint), FloatPoint(rect.maxX() - bottomRightRadius.width() * gCircleControlPoint, rect.maxY()), FloatPoint(rect.maxX() - bottomRightRadius.width(), rect.maxY())); addLineTo(FloatPoint(rect.x() + bottomLeftRadius.width(), rect.maxY())); if (bottomLeftRadius.width() > 0 || bottomLeftRadius.height() > 0) addBezierCurveTo(FloatPoint(rect.x() + bottomLeftRadius.width() * gCircleControlPoint, rect.maxY()), FloatPoint(rect.x(), rect.maxY() - bottomLeftRadius.height() * gCircleControlPoint), FloatPoint(rect.x(), rect.maxY() - bottomLeftRadius.height())); addLineTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height())); if (topLeftRadius.width() > 0 || topLeftRadius.height() > 0) addBezierCurveTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height() * gCircleControlPoint), FloatPoint(rect.x() + topLeftRadius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.x() + topLeftRadius.width(), rect.y())); closeSubpath(); }
void KdPath::addRoundedRect(const FloatRect& rect, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius) { if (rect.isEmpty()) return; if (rect.width() < topLeftRadius.width() + topRightRadius.width() || rect.width() < bottomLeftRadius.width() + bottomRightRadius.width() || rect.height() < topLeftRadius.height() + bottomLeftRadius.height() || rect.height() < topRightRadius.height() + bottomRightRadius.height()) { // If all the radii cannot be accommodated, return a rect. addRect(rect); return; } moveTo(FloatPoint(rect.x() + topLeftRadius.width(), rect.y())); addLineTo(FloatPoint(rect.x() + rect.width() - topRightRadius.width(), rect.y())); addBezierCurveTo(FloatPoint(rect.x() + rect.width() - topRightRadius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.x() + rect.width(), rect.y() + topRightRadius.height() * gCircleControlPoint), FloatPoint(rect.x() + rect.width(), rect.y() + topRightRadius.height())); addLineTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - bottomRightRadius.height())); addBezierCurveTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - bottomRightRadius.height() * gCircleControlPoint), FloatPoint(rect.x() + rect.width() - bottomRightRadius.width() * gCircleControlPoint, rect.y() + rect.height()), FloatPoint(rect.x() + rect.width() - bottomRightRadius.width(), rect.y() + rect.height())); addLineTo(FloatPoint(rect.x() + bottomLeftRadius.width(), rect.y() + rect.height())); addBezierCurveTo(FloatPoint(rect.x() + bottomLeftRadius.width() * gCircleControlPoint, rect.y() + rect.height()), FloatPoint(rect.x(), rect.y() + rect.height() - bottomLeftRadius.height() * gCircleControlPoint), FloatPoint(rect.x(), rect.y() + rect.height() - bottomLeftRadius.height())); addLineTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height())); addBezierCurveTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height() * gCircleControlPoint), FloatPoint(rect.x() + topLeftRadius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.x() + topLeftRadius.width(), rect.y())); closeSubpath(); }
void Path::addArcTo(const FloatPoint& point1, const FloatPoint& point2, float radius) { // See http://philip.html5.org/tests/canvas/suite/tests/spec.html#arcto. const FloatPoint& point0 = m_path->m_currentPoint; if (!radius || point0 == point1 || point1 == point2) { addLineTo(point1); return; } FloatSize v01 = point0 - point1; FloatSize v21 = point2 - point1; // sin(A - B) = sin(A) * cos(B) - sin(B) * cos(A) double cross = v01.width() * v21.height() - v01.height() * v21.width(); if (fabs(cross) < 1E-10) { // on one line addLineTo(point1); return; } double d01 = hypot(v01.width(), v01.height()); double d21 = hypot(v21.width(), v21.height()); double angle = (piDouble - fabs(asin(cross / (d01 * d21)))) * 0.5; double span = radius * tan(angle); double rate = span / d01; FloatPoint startPoint = FloatPoint(point1.x() + v01.width() * rate, point1.y() + v01.height() * rate); rate = span / d21; FloatPoint endPoint = FloatPoint(point1.x() + v21.width() * rate, point1.y() + v21.height() * rate); // Fa: large arc flag, makes the difference between SCWARC_TO and LCWARC_TO // respectively SCCWARC_TO and LCCWARC_TO arcs. We always use small // arcs for arcTo(), as the arc is defined as the "shortest arc" of the // circle specified in HTML 5. // Fs: sweep flag, specifying whether the arc is drawn in increasing (true) // or decreasing (0) direction. const bool anticlockwise = cross < 0; // Translate the large arc and sweep flags into an OpenVG segment command. const VGubyte segmentCommand = anticlockwise ? VG_SCCWARC_TO_ABS : VG_SCWARC_TO_ABS; const VGubyte pathSegments[] = { VG_LINE_TO_ABS, segmentCommand }; const VGfloat pathData[] = { startPoint.x(), startPoint.y(), radius, radius, 0, endPoint.x(), endPoint.y() }; m_path->makeCompatibleContextCurrent(); vgAppendPathData(m_path->vgPath(), 2, pathSegments, pathData); ASSERT_VG_NO_ERROR(); m_path->m_currentPoint = endPoint; }
void Path::addBeziersForRoundedRect(const FloatRect& rect, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius) { bool equalWidths = (topLeftRadius.width() == topRightRadius.width() && topRightRadius.width() == bottomLeftRadius.width() && bottomLeftRadius.width() == bottomRightRadius.width()); bool equalHeights = (topLeftRadius.height() == bottomLeftRadius.height() && bottomLeftRadius.height() == topRightRadius.height() && topRightRadius.height() == bottomRightRadius.height()); if (equalWidths && equalHeights) { CGPathAddRoundedRect(m_path, 0, rect, topLeftRadius.width(), topLeftRadius.height()); return; } moveTo(FloatPoint(rect.x() + topLeftRadius.width(), rect.y())); addLineTo(FloatPoint(rect.maxX() - topRightRadius.width(), rect.y())); addBezierCurveTo(FloatPoint(rect.maxX() - topRightRadius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.maxX(), rect.y() + topRightRadius.height() * gCircleControlPoint), FloatPoint(rect.maxX(), rect.y() + topRightRadius.height())); addLineTo(FloatPoint(rect.maxX(), rect.maxY() - bottomRightRadius.height())); addBezierCurveTo(FloatPoint(rect.maxX(), rect.maxY() - bottomRightRadius.height() * gCircleControlPoint), FloatPoint(rect.maxX() - bottomRightRadius.width() * gCircleControlPoint, rect.maxY()), FloatPoint(rect.maxX() - bottomRightRadius.width(), rect.maxY())); addLineTo(FloatPoint(rect.x() + bottomLeftRadius.width(), rect.maxY())); addBezierCurveTo(FloatPoint(rect.x() + bottomLeftRadius.width() * gCircleControlPoint, rect.maxY()), FloatPoint(rect.x(), rect.maxY() - bottomLeftRadius.height() * gCircleControlPoint), FloatPoint(rect.x(), rect.maxY() - bottomLeftRadius.height())); addLineTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height())); addBezierCurveTo(FloatPoint(rect.x(), rect.y() + topLeftRadius.height() * gCircleControlPoint), FloatPoint(rect.x() + topLeftRadius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.x() + topLeftRadius.width(), rect.y())); closeSubpath(); }
void KdPath::addRoundedRect(const FloatRect& rect, const FloatSize& roundingRadii) { if (rect.isEmpty()) return; FloatSize radius(roundingRadii); FloatSize halfSize(rect.width() / 2, rect.height() / 2); // If rx is greater than half of the width of the rectangle // then set rx to half of the width (required in SVG spec) if (radius.width() > halfSize.width()) radius.setWidth(halfSize.width()); // If ry is greater than half of the height of the rectangle // then set ry to half of the height (required in SVG spec) if (radius.height() > halfSize.height()) radius.setHeight(halfSize.height()); moveTo(FloatPoint(rect.x() + radius.width(), rect.y())); if (radius.width() < halfSize.width()) addLineTo(FloatPoint(rect.x() + rect.width() - roundingRadii.width(), rect.y())); const int minAntiAliasingRadius = 3; // add by weolar ©╦╬БЁщ срио╫г if (radius.width() <= minAntiAliasingRadius && radius.height() <= minAntiAliasingRadius) { addLineTo(FloatPoint(rect.x() + rect.width(), rect.y() + radius.height())); } else addBezierCurveTo(FloatPoint(rect.x() + rect.width() - radius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.x() + rect.width(), rect.y() + radius.height() * gCircleControlPoint), FloatPoint(rect.x() + rect.width(), rect.y() + radius.height())); if (radius.height() < halfSize.height()) addLineTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - radius.height())); // add by weolar сроб╫г if (radius.width() <= minAntiAliasingRadius && radius.height() <= minAntiAliasingRadius) { addLineTo(FloatPoint(rect.x() + rect.width() - radius.width(), rect.y() + rect.height())); } else addBezierCurveTo(FloatPoint(rect.x() + rect.width(), rect.y() + rect.height() - radius.height() * gCircleControlPoint), FloatPoint(rect.x() + rect.width() - radius.width() * gCircleControlPoint, rect.y() + rect.height()), FloatPoint(rect.x() + rect.width() - radius.width(), rect.y() + rect.height())); if (radius.width() < halfSize.width()) addLineTo(FloatPoint(rect.x() + radius.width(), rect.y() + rect.height())); // add by weolar вСоб╫г if (radius.width() <= minAntiAliasingRadius && radius.height() <= minAntiAliasingRadius) { addLineTo(FloatPoint(rect.x(), rect.y() + rect.height() - radius.height())); } else addBezierCurveTo(FloatPoint(rect.x() + radius.width() * gCircleControlPoint, rect.y() + rect.height()), FloatPoint(rect.x(), rect.y() + rect.height() - radius.height() * gCircleControlPoint), FloatPoint(rect.x(), rect.y() + rect.height() - radius.height())); if (radius.height() < halfSize.height()) addLineTo(FloatPoint(rect.x(), rect.y() + radius.height())); // add by weolar вСио╫г if (radius.width() <= minAntiAliasingRadius && radius.height() <= minAntiAliasingRadius) { addLineTo(FloatPoint(rect.x() + radius.width(), rect.y())); } else addBezierCurveTo(FloatPoint(rect.x(), rect.y() + radius.height() * gCircleControlPoint), FloatPoint(rect.x() + radius.width() * gCircleControlPoint, rect.y()), FloatPoint(rect.x() + radius.width(), rect.y())); closeSubpath(); }
void Path::addEllipse(const FloatRect& rect) { if (rect.isEmpty()) { moveTo(rect.location()); if (rect.width() > FLT_EPSILON) { addLineTo(FloatPoint(rect.x() + rect.width(), rect.y())); closeSubpath(); } else if (rect.height() > FLT_EPSILON) { addLineTo(FloatPoint(rect.x(), rect.y() + rect.height())); closeSubpath(); } return; } m_path->makeCompatibleContextCurrent(); VGUErrorCode error = vguEllipse(m_path->vgPath(), rect.x() + rect.width() / 2.0, rect.y() + rect.height() / 2.0, rect.width(), rect.height()); ASSERT(error == VGU_NO_ERROR); }