mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:07:35 +00:00
LibWeb: Extract CanvasText class from CRC2D
This commit is contained in:
parent
62b561e2e1
commit
7cf42ede68
4 changed files with 44 additions and 10 deletions
28
Userland/Libraries/LibWeb/HTML/Canvas/CanvasText.h
Normal file
28
Userland/Libraries/LibWeb/HTML/Canvas/CanvasText.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Optional.h>
|
||||||
|
#include <AK/String.h>
|
||||||
|
#include <LibWeb/HTML/TextMetrics.h>
|
||||||
|
|
||||||
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/canvas.html#canvastext
|
||||||
|
class CanvasText {
|
||||||
|
public:
|
||||||
|
virtual ~CanvasText() = default;
|
||||||
|
|
||||||
|
virtual void fill_text(String const&, float x, float y, Optional<double> max_width) = 0;
|
||||||
|
virtual void stroke_text(String const&, float x, float y, Optional<double> max_width) = 0;
|
||||||
|
virtual RefPtr<TextMetrics> measure_text(String const& text) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CanvasText() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
8
Userland/Libraries/LibWeb/HTML/Canvas/CanvasText.idl
Normal file
8
Userland/Libraries/LibWeb/HTML/Canvas/CanvasText.idl
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#import <HTML/TextMetrics.idl>
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/canvas.html#canvastext
|
||||||
|
interface mixin CanvasText {
|
||||||
|
undefined fillText(DOMString text, unrestricted double x, unrestricted double y, optional unrestricted double maxWidth);
|
||||||
|
undefined strokeText(DOMString text, unrestricted double x, unrestricted double y, optional unrestricted double maxWidth);
|
||||||
|
TextMetrics measureText(DOMString text);
|
||||||
|
};
|
|
@ -21,6 +21,7 @@
|
||||||
#include <LibWeb/HTML/Canvas/CanvasPath.h>
|
#include <LibWeb/HTML/Canvas/CanvasPath.h>
|
||||||
#include <LibWeb/HTML/Canvas/CanvasRect.h>
|
#include <LibWeb/HTML/Canvas/CanvasRect.h>
|
||||||
#include <LibWeb/HTML/Canvas/CanvasState.h>
|
#include <LibWeb/HTML/Canvas/CanvasState.h>
|
||||||
|
#include <LibWeb/HTML/Canvas/CanvasText.h>
|
||||||
#include <LibWeb/HTML/Canvas/CanvasTransform.h>
|
#include <LibWeb/HTML/Canvas/CanvasTransform.h>
|
||||||
#include <LibWeb/HTML/CanvasGradient.h>
|
#include <LibWeb/HTML/CanvasGradient.h>
|
||||||
#include <LibWeb/Layout/InlineNode.h>
|
#include <LibWeb/Layout/InlineNode.h>
|
||||||
|
@ -40,7 +41,8 @@ class CanvasRenderingContext2D
|
||||||
, public CanvasTransform<CanvasRenderingContext2D>
|
, public CanvasTransform<CanvasRenderingContext2D>
|
||||||
, public CanvasFillStrokeStyles<CanvasRenderingContext2D>
|
, public CanvasFillStrokeStyles<CanvasRenderingContext2D>
|
||||||
, public CanvasRect
|
, public CanvasRect
|
||||||
, public CanvasDrawPath {
|
, public CanvasDrawPath
|
||||||
|
, public CanvasText {
|
||||||
|
|
||||||
AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D);
|
AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D);
|
||||||
AK_MAKE_NONMOVABLE(CanvasRenderingContext2D);
|
AK_MAKE_NONMOVABLE(CanvasRenderingContext2D);
|
||||||
|
@ -66,8 +68,8 @@ public:
|
||||||
virtual void stroke() override;
|
virtual void stroke() override;
|
||||||
virtual void stroke(Path2D const& path) override;
|
virtual void stroke(Path2D const& path) override;
|
||||||
|
|
||||||
void fill_text(String const&, float x, float y, Optional<double> max_width);
|
virtual void fill_text(String const&, float x, float y, Optional<double> max_width) override;
|
||||||
void stroke_text(String const&, float x, float y, Optional<double> max_width);
|
virtual void stroke_text(String const&, float x, float y, Optional<double> max_width) override;
|
||||||
|
|
||||||
virtual void fill(String const& fill_rule) override;
|
virtual void fill(String const& fill_rule) override;
|
||||||
virtual void fill(Path2D& path, String const& fill_rule) override;
|
virtual void fill(Path2D& path, String const& fill_rule) override;
|
||||||
|
@ -80,7 +82,7 @@ public:
|
||||||
|
|
||||||
NonnullRefPtr<HTMLCanvasElement> canvas_for_binding() const;
|
NonnullRefPtr<HTMLCanvasElement> canvas_for_binding() const;
|
||||||
|
|
||||||
RefPtr<TextMetrics> measure_text(String const& text);
|
virtual RefPtr<TextMetrics> measure_text(String const& text) override;
|
||||||
|
|
||||||
virtual void clip() override;
|
virtual void clip() override;
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,18 @@
|
||||||
#import <HTML/HTMLCanvasElement.idl>
|
#import <HTML/HTMLCanvasElement.idl>
|
||||||
#import <HTML/HTMLImageElement.idl>
|
#import <HTML/HTMLImageElement.idl>
|
||||||
#import <HTML/ImageData.idl>
|
#import <HTML/ImageData.idl>
|
||||||
#import <HTML/TextMetrics.idl>
|
|
||||||
#import <HTML/Canvas/CanvasDrawPath.idl>
|
#import <HTML/Canvas/CanvasDrawPath.idl>
|
||||||
#import <HTML/Canvas/CanvasFillStrokeStyles.idl>
|
#import <HTML/Canvas/CanvasFillStrokeStyles.idl>
|
||||||
#import <HTML/Canvas/CanvasPath.idl>
|
#import <HTML/Canvas/CanvasPath.idl>
|
||||||
#import <HTML/Canvas/CanvasRect.idl>
|
#import <HTML/Canvas/CanvasRect.idl>
|
||||||
#import <HTML/Canvas/CanvasState.idl>
|
#import <HTML/Canvas/CanvasState.idl>
|
||||||
|
#import <HTML/Canvas/CanvasText.idl>
|
||||||
#import <HTML/Canvas/CanvasTransform.idl>
|
#import <HTML/Canvas/CanvasTransform.idl>
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/canvas.html#canvasrenderingcontext2d
|
// https://html.spec.whatwg.org/multipage/canvas.html#canvasrenderingcontext2d
|
||||||
[Exposed=Window]
|
[Exposed=Window]
|
||||||
interface CanvasRenderingContext2D {
|
interface CanvasRenderingContext2D {
|
||||||
|
|
||||||
undefined fillText(DOMString text, double x, double y, optional double maxWidth);
|
|
||||||
undefined strokeText(DOMString text, double x, double y, optional double maxWidth);
|
|
||||||
|
|
||||||
undefined drawImage((HTMLImageElement or HTMLCanvasElement) image, double dx, double dy);
|
undefined drawImage((HTMLImageElement or HTMLCanvasElement) image, double dx, double dy);
|
||||||
undefined drawImage((HTMLImageElement or HTMLCanvasElement) image, double dx, double dy, double dw, double dh);
|
undefined drawImage((HTMLImageElement or HTMLCanvasElement) image, double dx, double dy, double dw, double dh);
|
||||||
undefined drawImage((HTMLImageElement or HTMLCanvasElement) image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh);
|
undefined drawImage((HTMLImageElement or HTMLCanvasElement) image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh);
|
||||||
|
@ -28,8 +25,6 @@ interface CanvasRenderingContext2D {
|
||||||
|
|
||||||
[ImplementedAs=canvas_for_binding] readonly attribute HTMLCanvasElement canvas;
|
[ImplementedAs=canvas_for_binding] readonly attribute HTMLCanvasElement canvas;
|
||||||
|
|
||||||
TextMetrics measureText(DOMString text);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CanvasRenderingContext2D includes CanvasState;
|
CanvasRenderingContext2D includes CanvasState;
|
||||||
|
@ -37,4 +32,5 @@ CanvasRenderingContext2D includes CanvasTransform;
|
||||||
CanvasRenderingContext2D includes CanvasFillStrokeStyles;
|
CanvasRenderingContext2D includes CanvasFillStrokeStyles;
|
||||||
CanvasRenderingContext2D includes CanvasRect;
|
CanvasRenderingContext2D includes CanvasRect;
|
||||||
CanvasRenderingContext2D includes CanvasDrawPath;
|
CanvasRenderingContext2D includes CanvasDrawPath;
|
||||||
|
CanvasRenderingContext2D includes CanvasText;
|
||||||
CanvasRenderingContext2D includes CanvasPath;
|
CanvasRenderingContext2D includes CanvasPath;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue