mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-02 14:19:48 +00:00
LibWeb: Add BasicShapeStyleValue
to represent CSS basic shapes
See: https://www.w3.org/TR/css-shapes-1/#basic-shape-functions This patch only implements the `polygon()` basic shape (with the rest left as FIXMEs).
This commit is contained in:
parent
71ccd8ad25
commit
5f17d9b34a
Notes:
sideshowbarker
2024-07-17 04:49:48 +09:00
Author: https://github.com/MacDue
Commit: 5f17d9b34a
Pull-request: https://github.com/SerenityOS/serenity/pull/24446
6 changed files with 126 additions and 0 deletions
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright (c) 2024, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "BasicShapeStyleValue.h"
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
Gfx::Path Polygon::to_path(CSSPixelRect reference_box, Layout::Node const& node) const
|
||||
{
|
||||
Gfx::Path path;
|
||||
bool first = true;
|
||||
for (auto const& point : points) {
|
||||
Gfx::FloatPoint resolved_point {
|
||||
static_cast<float>(point.x.to_px(node, reference_box.width())),
|
||||
static_cast<float>(point.y.to_px(node, reference_box.height()))
|
||||
};
|
||||
if (first)
|
||||
path.move_to(resolved_point);
|
||||
else
|
||||
path.line_to(resolved_point);
|
||||
first = false;
|
||||
}
|
||||
path.close();
|
||||
return path;
|
||||
}
|
||||
|
||||
String Polygon::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("polygon("sv);
|
||||
bool first = true;
|
||||
for (auto const& point : points) {
|
||||
if (!first)
|
||||
builder.append(',');
|
||||
builder.appendff("{} {}", point.x, point.y);
|
||||
first = false;
|
||||
}
|
||||
builder.append(')');
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
BasicShapeStyleValue::~BasicShapeStyleValue() = default;
|
||||
|
||||
Gfx::Path BasicShapeStyleValue::to_path(CSSPixelRect reference_box, Layout::Node const& node) const
|
||||
{
|
||||
return m_basic_shape.visit([&](auto const& shape) {
|
||||
return shape.to_path(reference_box, node);
|
||||
});
|
||||
}
|
||||
|
||||
String BasicShapeStyleValue::to_string() const
|
||||
{
|
||||
return m_basic_shape.visit([](auto const& shape) {
|
||||
return shape.to_string();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue