const Path& BasicShapeCircle::path(const FloatRect& boundingBox) { float centerX = floatValueForCenterCoordinate(m_centerX, boundingBox.width()); float centerY = floatValueForCenterCoordinate(m_centerY, boundingBox.height()); float radius = floatValueForRadiusInBox(boundingBox.width(), boundingBox.height()); return cachedEllipsePath(FloatRect(centerX - radius + boundingBox.x(), centerY - radius + boundingBox.y(), radius * 2, radius * 2)); }
float BasicShapeCircle::floatValueForRadiusInBox(float boxWidth, float boxHeight) const { if (m_radius.type() == BasicShapeRadius::Value) return floatValueForLength(m_radius.value(), sqrtf((boxWidth * boxWidth + boxHeight * boxHeight) / 2)); float centerX = floatValueForCenterCoordinate(m_centerX, boxWidth); float centerY = floatValueForCenterCoordinate(m_centerY, boxHeight); if (m_radius.type() == BasicShapeRadius::ClosestSide) return std::min(std::min(centerX, boxWidth - centerX), std::min(centerY, boxHeight - centerY)); // If radius.type() == BasicShapeRadius::FarthestSide. return std::max(std::max(centerX, boxWidth - centerX), std::max(centerY, boxHeight - centerY)); }
void BasicShapeEllipse::path(Path& path, const FloatRect& boundingBox) { ASSERT(path.isEmpty()); float centerX = floatValueForCenterCoordinate(m_centerX, boundingBox.width()); float centerY = floatValueForCenterCoordinate(m_centerY, boundingBox.height()); float radiusX = floatValueForRadiusInBox(m_radiusX, centerX, boundingBox.width()); float radiusY = floatValueForRadiusInBox(m_radiusY, centerY, boundingBox.height()); path.addEllipse(FloatRect( centerX - radiusX + boundingBox.x(), centerY - radiusY + boundingBox.y(), radiusX * 2, radiusY * 2)); }
std::unique_ptr<Shape> Shape::createShape(const BasicShape* basicShape, const LayoutSize& logicalBoxSize, WritingMode writingMode, float margin) { ASSERT(basicShape); bool horizontalWritingMode = isHorizontalWritingMode(writingMode); float boxWidth = horizontalWritingMode ? logicalBoxSize.width() : logicalBoxSize.height(); float boxHeight = horizontalWritingMode ? logicalBoxSize.height() : logicalBoxSize.width(); std::unique_ptr<Shape> shape; switch (basicShape->type()) { case BasicShape::BasicShapeCircleType: { const BasicShapeCircle* circle = static_cast<const BasicShapeCircle*>(basicShape); float centerX = floatValueForCenterCoordinate(circle->centerX(), boxWidth); float centerY = floatValueForCenterCoordinate(circle->centerY(), boxHeight); float radius = circle->floatValueForRadiusInBox(boxWidth, boxHeight); FloatPoint logicalCenter = physicalPointToLogical(FloatPoint(centerX, centerY), logicalBoxSize.height(), writingMode); shape = createCircleShape(logicalCenter, radius); break; } case BasicShape::BasicShapeEllipseType: { const BasicShapeEllipse* ellipse = static_cast<const BasicShapeEllipse*>(basicShape); float centerX = floatValueForCenterCoordinate(ellipse->centerX(), boxWidth); float centerY = floatValueForCenterCoordinate(ellipse->centerY(), boxHeight); float radiusX = ellipse->floatValueForRadiusInBox(ellipse->radiusX(), centerX, boxWidth); float radiusY = ellipse->floatValueForRadiusInBox(ellipse->radiusY(), centerY, boxHeight); FloatPoint logicalCenter = physicalPointToLogical(FloatPoint(centerX, centerY), logicalBoxSize.height(), writingMode); shape = createEllipseShape(logicalCenter, FloatSize(radiusX, radiusY)); break; } case BasicShape::BasicShapePolygonType: { const BasicShapePolygon& polygon = *static_cast<const BasicShapePolygon*>(basicShape); const Vector<Length>& values = polygon.values(); size_t valuesSize = values.size(); ASSERT(!(valuesSize % 2)); std::unique_ptr<Vector<FloatPoint>> vertices = std::make_unique<Vector<FloatPoint>>(valuesSize / 2); for (unsigned i = 0; i < valuesSize; i += 2) { FloatPoint vertex( floatValueForLength(values.at(i), boxWidth), floatValueForLength(values.at(i + 1), boxHeight)); (*vertices)[i / 2] = physicalPointToLogical(vertex, logicalBoxSize.height(), writingMode); } shape = createPolygonShape(WTF::move(vertices), polygon.windRule()); break; } case BasicShape::BasicShapeInsetType: { const BasicShapeInset& inset = *static_cast<const BasicShapeInset*>(basicShape); float left = floatValueForLength(inset.left(), boxWidth); float top = floatValueForLength(inset.top(), boxHeight); FloatRect rect(left, top, std::max<float>(boxWidth - left - floatValueForLength(inset.right(), boxWidth), 0), std::max<float>(boxHeight - top - floatValueForLength(inset.bottom(), boxHeight), 0)); FloatRect logicalRect = physicalRectToLogical(rect, logicalBoxSize.height(), writingMode); FloatSize boxSize(boxWidth, boxHeight); FloatSize topLeftRadius = physicalSizeToLogical(floatSizeForLengthSize(inset.topLeftRadius(), boxSize), writingMode); FloatSize topRightRadius = physicalSizeToLogical(floatSizeForLengthSize(inset.topRightRadius(), boxSize), writingMode); FloatSize bottomLeftRadius = physicalSizeToLogical(floatSizeForLengthSize(inset.bottomLeftRadius(), boxSize), writingMode); FloatSize bottomRightRadius = physicalSizeToLogical(floatSizeForLengthSize(inset.bottomRightRadius(), boxSize), writingMode); FloatRoundedRect::Radii cornerRadii(topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius); cornerRadii.scale(calcBorderRadiiConstraintScaleFor(logicalRect, cornerRadii)); shape = createInsetShape(FloatRoundedRect(logicalRect, cornerRadii)); break; } default: ASSERT_NOT_REACHED(); } shape->m_writingMode = writingMode; shape->m_margin = margin; return shape; }