mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:47:36 +00:00
LibWeb: Add a naive implemention of CanvasRenderingContext2D::fill_text
This doesnt actually account for several unimplemented attributes (like ltr/rtl, alignment, etc) yet, so this should be expanded in the future.
This commit is contained in:
parent
a257ef0f35
commit
00114ab01d
3 changed files with 20 additions and 0 deletions
|
@ -163,6 +163,22 @@ OwnPtr<Gfx::Painter> CanvasRenderingContext2D::painter()
|
|||
return make<Gfx::Painter>(*m_element->bitmap());
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::fill_text(const String& text, float x, float y, Optional<double> max_width)
|
||||
{
|
||||
if (max_width.has_value() && max_width.value() <= 0)
|
||||
return;
|
||||
|
||||
auto painter = this->painter();
|
||||
if (!painter)
|
||||
return;
|
||||
|
||||
// FIXME: painter only supports integer rects for text right now, so this effectively chops off any fractional position
|
||||
auto text_rect = Gfx::IntRect(x, y, max_width.has_value() ? max_width.value() : painter->font().width(text), painter->font().glyph_height());
|
||||
auto transformed_rect = m_transform.map(text_rect);
|
||||
painter->draw_text(transformed_rect, text, Gfx::TextAlignment::TopLeft, m_fill_style);
|
||||
did_draw(transformed_rect.to<float>());
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::begin_path()
|
||||
{
|
||||
m_path = Gfx::Path();
|
||||
|
|
|
@ -80,6 +80,8 @@ public:
|
|||
void rect(float x, float y, float width, float height);
|
||||
void stroke();
|
||||
|
||||
void fill_text(const String&, float x, float y, Optional<double> max_width);
|
||||
|
||||
// FIXME: We should only have one fill(), really. Fix the wrapper generator!
|
||||
void fill(Gfx::Painter::WindingRule);
|
||||
void fill(const String& fill_rule);
|
||||
|
|
|
@ -20,6 +20,8 @@ interface CanvasRenderingContext2D {
|
|||
undefined ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, optional boolean counterclockwise = false);
|
||||
undefined rect(double x, double y, double width, double height);
|
||||
|
||||
undefined fillText(DOMString text, double x, double y, optional double maxWidth);
|
||||
|
||||
undefined drawImage(HTMLImageElement image, double dx, double dy);
|
||||
|
||||
attribute DOMString fillStyle;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue