mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:08:10 +00:00
LibWeb: Extract CanvasPathDrawingStyles class from CRC2D
This commit is contained in:
parent
53b9f36413
commit
9f71d65005
4 changed files with 57 additions and 8 deletions
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/HTML/Canvas/CanvasState.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#canvaspathdrawingstyles
|
||||
template<typename IncludingClass>
|
||||
class CanvasPathDrawingStyles {
|
||||
public:
|
||||
~CanvasPathDrawingStyles() = default;
|
||||
|
||||
void set_line_width(float line_width) { my_drawing_state().line_width = line_width; }
|
||||
float line_width() const { return my_drawing_state().line_width; }
|
||||
|
||||
protected:
|
||||
CanvasPathDrawingStyles() = default;
|
||||
|
||||
private:
|
||||
CanvasState::DrawingState& my_drawing_state() { return reinterpret_cast<IncludingClass&>(*this).drawing_state(); }
|
||||
CanvasState::DrawingState const& my_drawing_state() const { return reinterpret_cast<IncludingClass const&>(*this).drawing_state(); }
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
// https://html.spec.whatwg.org/multipage/canvas.html#canvaslinecap
|
||||
enum CanvasLineCap { "butt", "round", "square" };
|
||||
enum CanvasLineJoin { "round", "bevel", "miter" };
|
||||
enum CanvasTextAlign { "start", "end", "left", "right", "center" };
|
||||
enum CanvasTextBaseline { "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" };
|
||||
enum CanvasDirection { "ltr", "rtl", "inherit" };
|
||||
enum CanvasFontKerning { "auto", "normal", "none" };
|
||||
enum CanvasFontStretch { "ultra-condensed", "extra-condensed", "condensed", "semi-condensed", "normal", "semi-expanded", "expanded", "extra-expanded", "ultra-expanded" };
|
||||
enum CanvasFontVariantCaps { "normal", "small-caps", "all-small-caps", "petite-caps", "all-petite-caps", "unicase", "titling-caps" };
|
||||
enum CanvasTextRendering { "auto", "optimizeSpeed", "optimizeLegibility", "geometricPrecision" };
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/canvas.html#canvaspathdrawingstyles
|
||||
interface mixin CanvasPathDrawingStyles {
|
||||
attribute unrestricted double lineWidth;
|
||||
// FIXME: attribute CanvasLineCap lineCap;
|
||||
// FIXME: attribute CanvasLineJoin lineJoin;
|
||||
// FIXME: attribute unrestricted double miterLimit;
|
||||
|
||||
// FIXME: undefined setLineDash(sequence<unrestricted double> segments);
|
||||
// FIXME: sequence<unrestricted double> getLineDash();
|
||||
// FIXME: attribute unrestricted double lineDashOffset;
|
||||
};
|
|
@ -21,6 +21,7 @@
|
|||
#include <LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h>
|
||||
#include <LibWeb/HTML/Canvas/CanvasImageData.h>
|
||||
#include <LibWeb/HTML/Canvas/CanvasPath.h>
|
||||
#include <LibWeb/HTML/Canvas/CanvasPathDrawingStyles.h>
|
||||
#include <LibWeb/HTML/Canvas/CanvasRect.h>
|
||||
#include <LibWeb/HTML/Canvas/CanvasState.h>
|
||||
#include <LibWeb/HTML/Canvas/CanvasText.h>
|
||||
|
@ -46,7 +47,8 @@ class CanvasRenderingContext2D
|
|||
, public CanvasDrawPath
|
||||
, public CanvasText
|
||||
, public CanvasDrawImage
|
||||
, public CanvasImageData {
|
||||
, public CanvasImageData
|
||||
, public CanvasPathDrawingStyles<CanvasRenderingContext2D> {
|
||||
|
||||
AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D);
|
||||
AK_MAKE_NONMOVABLE(CanvasRenderingContext2D);
|
||||
|
@ -63,9 +65,6 @@ public:
|
|||
|
||||
virtual DOM::ExceptionOr<void> draw_image_internal(CanvasImageSource const&, float source_x, float source_y, float source_width, float source_height, float destination_x, float destination_y, float destination_width, float destination_height) override;
|
||||
|
||||
void set_line_width(float line_width) { drawing_state().line_width = line_width; }
|
||||
float line_width() const { return drawing_state().line_width; }
|
||||
|
||||
virtual void begin_path() override;
|
||||
virtual void stroke() override;
|
||||
virtual void stroke(Path2D const& path) override;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#import <HTML/Canvas/CanvasFillStrokeStyles.idl>
|
||||
#import <HTML/Canvas/CanvasImageData.idl>
|
||||
#import <HTML/Canvas/CanvasPath.idl>
|
||||
#import <HTML/Canvas/CanvasPathDrawingStyles.idl>
|
||||
#import <HTML/Canvas/CanvasRect.idl>
|
||||
#import <HTML/Canvas/CanvasState.idl>
|
||||
#import <HTML/Canvas/CanvasText.idl>
|
||||
|
@ -12,11 +13,7 @@
|
|||
// https://html.spec.whatwg.org/multipage/canvas.html#canvasrenderingcontext2d
|
||||
[Exposed=Window]
|
||||
interface CanvasRenderingContext2D {
|
||||
|
||||
attribute double lineWidth;
|
||||
|
||||
[ImplementedAs=canvas_for_binding] readonly attribute HTMLCanvasElement canvas;
|
||||
|
||||
};
|
||||
|
||||
CanvasRenderingContext2D includes CanvasState;
|
||||
|
@ -27,4 +24,5 @@ CanvasRenderingContext2D includes CanvasDrawPath;
|
|||
CanvasRenderingContext2D includes CanvasText;
|
||||
CanvasRenderingContext2D includes CanvasDrawImage;
|
||||
CanvasRenderingContext2D includes CanvasImageData;
|
||||
CanvasRenderingContext2D includes CanvasPathDrawingStyles;
|
||||
CanvasRenderingContext2D includes CanvasPath;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue