diff options
author | sin-ack <sin-ack@users.noreply.github.com> | 2021-12-30 22:15:38 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-04 22:41:07 +0000 |
commit | 9121cc7cae407e7d8a3e489f4df73ef400517c88 (patch) | |
tree | 5710d64074cdaac016d4f1ff04f7c6d7e7845907 /Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h | |
parent | 732e41714a6f89d1462d672ae2b6efe911f082f4 (diff) | |
download | serenity-9121cc7cae407e7d8a3e489f4df73ef400517c88.zip |
LibWeb: Implement CanvasRenderingContext2D.measureText
This requires an implementation of the "text preparation algorithm" as
specified here:
html.spec.whatwg.org/multipage/canvas.html#text-preparation-algorithm
However, we're missing a lot of things such as the
CanvasTextDrawingStyles interface, so most of the algorithm was not
implemented. Additionally, we also are not able to use a LineBox like
the algorithm suggests, because our layouting infra is not up to the
task yet. The prepare_text function does nothing other than figuring out
the width of the given text and return glyphs with offsets at the
moment.
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h')
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h index 99d05f6baf..2e0d502657 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h +++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h @@ -14,6 +14,8 @@ #include <LibGfx/Path.h> #include <LibWeb/Bindings/Wrappable.h> #include <LibWeb/DOM/ExceptionOr.h> +#include <LibWeb/Layout/InlineNode.h> +#include <LibWeb/Layout/LineBox.h> namespace Web::HTML { @@ -78,10 +80,24 @@ public: HTMLCanvasElement* canvas() { return m_element; } + RefPtr<TextMetrics> measure_text(String const& text); + private: explicit CanvasRenderingContext2D(HTMLCanvasElement&); + struct PreparedTextGlyph { + unsigned int c; + Gfx::IntPoint position; + }; + + struct PreparedText { + Vector<PreparedTextGlyph> glyphs; + Gfx::TextAlignment physical_alignment; + Gfx::IntRect bounding_box; + }; + void did_draw(const Gfx::FloatRect&); + PreparedText prepare_text(String const& text, float max_width = INFINITY); OwnPtr<Gfx::Painter> painter(); |