Example #1
0
void Path::addRoundedRect(const FloatRect& rect,
                          const FloatSize& roundingRadii) {
  if (rect.isEmpty())
    return;

  FloatSize radius(roundingRadii);
  FloatSize halfSize(rect.width() / 2, rect.height() / 2);

  // Apply the SVG corner radius constraints, per the rect section of the SVG
  // shapes spec: if one of rx,ry is negative, then the other corner radius
  // value is used. If both values are negative then rx = ry = 0. If rx is
  // greater than half of the width of the rectangle then set rx to half of the
  // width; ry is handled similarly.

  if (radius.width() < 0)
    radius.setWidth((radius.height() < 0) ? 0 : radius.height());

  if (radius.height() < 0)
    radius.setHeight(radius.width());

  if (radius.width() > halfSize.width())
    radius.setWidth(halfSize.width());

  if (radius.height() > halfSize.height())
    radius.setHeight(halfSize.height());

  addPathForRoundedRect(rect, radius, radius, radius, radius);
}
Example #2
0
void Path::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.
    // FIXME: Is this an error scenario, given that it appears the code in
    // FloatRoundedRect::constrainRadii() should be always called first? Should
    // we assert that this code is not reached? This fallback is very bad, since
    // it means that radii that are just barely too big due to rounding or
    // snapping will get completely ignored.
    addRect(rect);
    return;
  }

  addPathForRoundedRect(rect, topLeftRadius, topRightRadius, bottomLeftRadius,
                        bottomRightRadius);
}
Example #3
0
void Path::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;
    }

    addPathForRoundedRect(rect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
}