2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2021-04-09 09:09:48 +00:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-10 14:49:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-14 22:28:42 +00:00
|
|
|
#include <AK/Forward.h>
|
2023-03-08 19:49:00 +00:00
|
|
|
#include <AK/Memory.h>
|
2020-02-14 23:58:14 +00:00
|
|
|
#include <AK/NonnullRefPtr.h>
|
2022-02-22 21:55:01 +00:00
|
|
|
#include <AK/Utf8View.h>
|
2020-02-14 20:41:10 +00:00
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include <LibGfx/Color.h>
|
2022-04-09 07:28:38 +00:00
|
|
|
#include <LibGfx/Font/FontDatabase.h>
|
2020-02-14 22:28:42 +00:00
|
|
|
#include <LibGfx/Forward.h>
|
2023-01-10 01:07:06 +00:00
|
|
|
#include <LibGfx/Gradients.h>
|
2023-01-15 22:15:24 +00:00
|
|
|
#include <LibGfx/PaintStyle.h>
|
2020-02-14 20:41:10 +00:00
|
|
|
#include <LibGfx/Point.h>
|
|
|
|
#include <LibGfx/Rect.h>
|
|
|
|
#include <LibGfx/Size.h>
|
2020-02-06 11:04:00 +00:00
|
|
|
#include <LibGfx/TextAlignment.h>
|
2021-07-25 21:20:11 +00:00
|
|
|
#include <LibGfx/TextDirection.h>
|
2020-02-06 11:04:00 +00:00
|
|
|
#include <LibGfx/TextElision.h>
|
2021-07-25 21:20:11 +00:00
|
|
|
#include <LibGfx/TextWrapping.h>
|
2023-01-15 22:15:24 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
namespace Gfx {
|
|
|
|
|
2018-10-10 14:49:36 +00:00
|
|
|
class Painter {
|
|
|
|
public:
|
2022-11-28 15:02:08 +00:00
|
|
|
static constexpr int LINE_SPACING = 4;
|
|
|
|
|
2021-01-19 17:10:47 +00:00
|
|
|
explicit Painter(Gfx::Bitmap&);
|
2022-03-14 19:26:37 +00:00
|
|
|
~Painter() = default;
|
2020-05-10 10:58:33 +00:00
|
|
|
|
|
|
|
enum class LineStyle {
|
|
|
|
Solid,
|
|
|
|
Dotted,
|
2020-05-10 15:17:26 +00:00
|
|
|
Dashed,
|
2020-05-10 10:58:33 +00:00
|
|
|
};
|
|
|
|
|
2021-09-20 18:48:56 +00:00
|
|
|
enum class ScalingMode {
|
2022-12-04 20:23:53 +00:00
|
|
|
NearestFractional,
|
2021-09-20 18:48:56 +00:00
|
|
|
NearestNeighbor,
|
2022-06-03 15:16:38 +00:00
|
|
|
SmoothPixels,
|
2021-09-20 18:48:56 +00:00
|
|
|
BilinearBlend,
|
2022-10-10 19:54:06 +00:00
|
|
|
None,
|
2021-09-20 18:48:56 +00:00
|
|
|
};
|
|
|
|
|
2021-09-17 13:06:28 +00:00
|
|
|
void clear_rect(IntRect const&, Color);
|
|
|
|
void fill_rect(IntRect const&, Color);
|
2023-01-15 22:18:46 +00:00
|
|
|
void fill_rect(IntRect const&, PaintStyle const&);
|
2021-09-17 13:06:28 +00:00
|
|
|
void fill_rect_with_dither_pattern(IntRect const&, Color, Color);
|
2022-12-06 21:35:32 +00:00
|
|
|
void fill_rect_with_checkerboard(IntRect const&, IntSize, Color color_dark, Color color_light);
|
2021-09-17 13:06:28 +00:00
|
|
|
void fill_rect_with_gradient(Orientation, IntRect const&, Color gradient_start, Color gradient_end);
|
|
|
|
void fill_rect_with_gradient(IntRect const&, Color gradient_start, Color gradient_end);
|
2023-02-05 19:02:54 +00:00
|
|
|
void fill_rect_with_linear_gradient(IntRect const&, ReadonlySpan<ColorStop>, float angle, Optional<float> repeat_length = {});
|
|
|
|
void fill_rect_with_conic_gradient(IntRect const&, ReadonlySpan<ColorStop>, IntPoint center, float start_angle, Optional<float> repeat_length = {});
|
|
|
|
void fill_rect_with_radial_gradient(IntRect const&, ReadonlySpan<ColorStop>, IntPoint center, IntSize size, Optional<float> repeat_length = {});
|
2021-09-17 13:06:28 +00:00
|
|
|
void fill_rect_with_rounded_corners(IntRect const&, Color, int radius);
|
|
|
|
void fill_rect_with_rounded_corners(IntRect const&, Color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius);
|
|
|
|
void fill_ellipse(IntRect const&, Color);
|
|
|
|
void draw_rect(IntRect const&, Color, bool rough = false);
|
|
|
|
void draw_rect_with_thickness(IntRect const&, Color, int thickness);
|
|
|
|
void draw_focus_rect(IntRect const&, Color);
|
2022-12-06 20:27:44 +00:00
|
|
|
void draw_bitmap(IntPoint, CharacterBitmap const&, Color = Color());
|
|
|
|
void draw_bitmap(IntPoint, GlyphBitmap const&, Color = Color());
|
2021-09-20 18:48:56 +00:00
|
|
|
void draw_scaled_bitmap(IntRect const& dst_rect, Gfx::Bitmap const&, IntRect const& src_rect, float opacity = 1.0f, ScalingMode = ScalingMode::NearestNeighbor);
|
|
|
|
void draw_scaled_bitmap(IntRect const& dst_rect, Gfx::Bitmap const&, FloatRect const& src_rect, float opacity = 1.0f, ScalingMode = ScalingMode::NearestNeighbor);
|
2022-09-24 11:00:53 +00:00
|
|
|
void draw_scaled_bitmap_with_transform(IntRect const& dst_rect, Gfx::Bitmap const&, FloatRect const& src_rect, Gfx::AffineTransform const&, float opacity = 1.0f, ScalingMode = ScalingMode::NearestNeighbor);
|
2022-12-06 20:27:44 +00:00
|
|
|
void draw_triangle(IntPoint, IntPoint, IntPoint, Color);
|
2023-02-05 19:02:54 +00:00
|
|
|
void draw_triangle(IntPoint offset, ReadonlySpan<IntPoint>, Color);
|
2021-09-17 13:06:28 +00:00
|
|
|
void draw_ellipse_intersecting(IntRect const&, Color, int thickness = 1);
|
2022-12-06 20:27:44 +00:00
|
|
|
void set_pixel(IntPoint, Color, bool blend = false);
|
2022-03-10 02:21:02 +00:00
|
|
|
void set_pixel(int x, int y, Color color, bool blend = false) { set_pixel({ x, y }, color, blend); }
|
2022-12-06 20:27:44 +00:00
|
|
|
Optional<Color> get_pixel(IntPoint);
|
2022-09-15 07:31:29 +00:00
|
|
|
ErrorOr<NonnullRefPtr<Bitmap>> get_region_bitmap(IntRect const&, BitmapFormat format, Optional<IntRect&> actual_region = {});
|
2022-12-06 20:27:44 +00:00
|
|
|
void draw_line(IntPoint, IntPoint, Color, int thickness = 1, LineStyle style = LineStyle::Solid, Color alternate_color = Color::Transparent);
|
|
|
|
void draw_triangle_wave(IntPoint, IntPoint, Color color, int amplitude, int thickness = 1);
|
|
|
|
void draw_quadratic_bezier_curve(IntPoint control_point, IntPoint, IntPoint, Color, int thickness = 1, LineStyle style = LineStyle::Solid);
|
|
|
|
void draw_cubic_bezier_curve(IntPoint control_point_0, IntPoint control_point_1, IntPoint, IntPoint, Color, int thickness = 1, LineStyle style = LineStyle::Solid);
|
2023-02-10 09:52:14 +00:00
|
|
|
void draw_elliptical_arc(IntPoint p1, IntPoint p2, IntPoint center, FloatSize radii, float x_axis_rotation, float theta_1, float theta_delta, Color, int thickness = 1, LineStyle style = LineStyle::Solid);
|
2022-12-06 20:27:44 +00:00
|
|
|
void blit(IntPoint, Gfx::Bitmap const&, IntRect const& src_rect, float opacity = 1.0f, bool apply_alpha = true);
|
|
|
|
void blit_dimmed(IntPoint, Gfx::Bitmap const&, IntRect const& src_rect);
|
|
|
|
void blit_brightened(IntPoint, Gfx::Bitmap const&, IntRect const& src_rect);
|
|
|
|
void blit_filtered(IntPoint, Gfx::Bitmap const&, IntRect const& src_rect, Function<Color(Color)>);
|
2021-09-17 13:06:28 +00:00
|
|
|
void draw_tiled_bitmap(IntRect const& dst_rect, Gfx::Bitmap const&);
|
2022-12-06 20:27:44 +00:00
|
|
|
void blit_offset(IntPoint, Gfx::Bitmap const&, IntRect const& src_rect, IntPoint);
|
|
|
|
void blit_disabled(IntPoint, Gfx::Bitmap const&, IntRect const&, Palette const&);
|
2021-09-17 13:06:28 +00:00
|
|
|
void blit_tiled(IntRect const&, Gfx::Bitmap const&, IntRect const& src_rect);
|
2023-01-01 18:42:00 +00:00
|
|
|
void draw_text(FloatRect const&, StringView, Font const&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
|
|
|
void draw_text(FloatRect const&, StringView, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
|
|
|
void draw_text(FloatRect const&, Utf32View const&, Font const&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
|
|
|
void draw_text(FloatRect const&, Utf32View const&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
|
|
|
void draw_text(Function<void(FloatRect const&, Utf8CodePointIterator&)>, FloatRect const&, StringView, Font const&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
|
|
|
void draw_text(Function<void(FloatRect const&, Utf8CodePointIterator&)>, FloatRect const&, Utf8View const&, Font const&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
|
|
|
void draw_text(Function<void(FloatRect const&, Utf8CodePointIterator&)>, FloatRect const&, Utf32View const&, Font const&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
2021-11-10 23:55:02 +00:00
|
|
|
void draw_text(IntRect const&, StringView, Font const&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
|
|
|
void draw_text(IntRect const&, StringView, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
2021-09-17 13:06:28 +00:00
|
|
|
void draw_text(IntRect const&, Utf32View const&, Font const&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
|
|
|
void draw_text(IntRect const&, Utf32View const&, TextAlignment = TextAlignment::TopLeft, Color = Color::Black, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
2023-01-01 18:42:00 +00:00
|
|
|
void draw_text(Function<void(FloatRect const&, Utf8CodePointIterator&)>, IntRect const&, StringView, Font const&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
|
|
|
void draw_text(Function<void(FloatRect const&, Utf8CodePointIterator&)>, IntRect const&, Utf8View const&, Font const&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
|
|
|
void draw_text(Function<void(FloatRect const&, Utf8CodePointIterator&)>, IntRect const&, Utf32View const&, Font const&, TextAlignment = TextAlignment::TopLeft, TextElision = TextElision::None, TextWrapping = TextWrapping::DontWrap);
|
2021-11-10 23:55:02 +00:00
|
|
|
void draw_ui_text(Gfx::IntRect const&, StringView, Gfx::Font const&, TextAlignment, Gfx::Color);
|
2022-12-06 20:27:44 +00:00
|
|
|
void draw_glyph(IntPoint, u32, Color);
|
|
|
|
void draw_glyph(IntPoint, u32, Font const&, Color);
|
|
|
|
void draw_emoji(IntPoint, Gfx::Bitmap const&, Font const&);
|
|
|
|
void draw_glyph_or_emoji(IntPoint, u32, Font const&, Color);
|
|
|
|
void draw_glyph_or_emoji(IntPoint, Utf8CodePointIterator&, Font const&, Color);
|
2023-01-01 18:42:00 +00:00
|
|
|
void draw_glyph(FloatPoint, u32, Color);
|
|
|
|
void draw_glyph(FloatPoint, u32, Font const&, Color);
|
|
|
|
void draw_glyph_or_emoji(FloatPoint, u32, Font const&, Color);
|
|
|
|
void draw_glyph_or_emoji(FloatPoint, Utf8CodePointIterator&, Font const&, Color);
|
2022-12-06 20:27:44 +00:00
|
|
|
void draw_circle_arc_intersecting(IntRect const&, IntPoint, int radius, Color, int thickness);
|
2019-01-12 16:02:54 +00:00
|
|
|
|
2022-03-28 11:40:48 +00:00
|
|
|
// Streamlined text drawing routine that does no wrapping/elision/alignment.
|
2022-12-07 20:50:34 +00:00
|
|
|
void draw_text_run(IntPoint baseline_start, Utf8View const&, Font const&, Color);
|
2022-12-06 20:57:07 +00:00
|
|
|
void draw_text_run(FloatPoint baseline_start, Utf8View const&, Font const&, Color);
|
2022-03-28 11:40:48 +00:00
|
|
|
|
2021-05-15 21:33:21 +00:00
|
|
|
enum class CornerOrientation {
|
|
|
|
TopLeft,
|
|
|
|
TopRight,
|
|
|
|
BottomRight,
|
|
|
|
BottomLeft
|
|
|
|
};
|
2021-09-17 13:06:28 +00:00
|
|
|
void fill_rounded_corner(IntRect const&, int radius, Color, CornerOrientation);
|
2021-05-15 21:33:21 +00:00
|
|
|
|
2022-12-06 20:57:07 +00:00
|
|
|
static void for_each_line_segment_on_bezier_curve(FloatPoint control_point, FloatPoint p1, FloatPoint p2, Function<void(FloatPoint, FloatPoint)>&);
|
|
|
|
static void for_each_line_segment_on_bezier_curve(FloatPoint control_point, FloatPoint p1, FloatPoint p2, Function<void(FloatPoint, FloatPoint)>&&);
|
2020-05-06 07:25:12 +00:00
|
|
|
|
2022-12-06 20:57:07 +00:00
|
|
|
static void for_each_line_segment_on_cubic_bezier_curve(FloatPoint control_point_0, FloatPoint control_point_1, FloatPoint p1, FloatPoint p2, Function<void(FloatPoint, FloatPoint)>&);
|
|
|
|
static void for_each_line_segment_on_cubic_bezier_curve(FloatPoint control_point_0, FloatPoint control_point_1, FloatPoint p1, FloatPoint p2, Function<void(FloatPoint, FloatPoint)>&&);
|
2021-09-17 14:12:30 +00:00
|
|
|
|
2023-02-10 09:52:14 +00:00
|
|
|
static void for_each_line_segment_on_elliptical_arc(FloatPoint p1, FloatPoint p2, FloatPoint center, FloatSize radii, float x_axis_rotation, float theta_1, float theta_delta, Function<void(FloatPoint, FloatPoint)>&);
|
|
|
|
static void for_each_line_segment_on_elliptical_arc(FloatPoint p1, FloatPoint p2, FloatPoint center, FloatSize radii, float x_axis_rotation, float theta_1, float theta_delta, Function<void(FloatPoint, FloatPoint)>&&);
|
2020-07-22 06:46:15 +00:00
|
|
|
|
2021-09-17 13:06:28 +00:00
|
|
|
void stroke_path(Path const&, Color, int thickness);
|
2020-04-16 19:03:17 +00:00
|
|
|
|
2020-05-06 07:25:12 +00:00
|
|
|
enum class WindingRule {
|
|
|
|
Nonzero,
|
|
|
|
EvenOdd,
|
|
|
|
};
|
2021-09-17 11:41:03 +00:00
|
|
|
void fill_path(Path const&, Color, WindingRule rule = WindingRule::Nonzero);
|
2023-01-15 22:15:24 +00:00
|
|
|
void fill_path(Path const&, PaintStyle const& paint_style, WindingRule rule = WindingRule::Nonzero);
|
2020-05-06 07:25:12 +00:00
|
|
|
|
2021-11-28 15:09:38 +00:00
|
|
|
Font const& font() const
|
|
|
|
{
|
|
|
|
if (!state().font)
|
|
|
|
return FontDatabase::default_font();
|
|
|
|
return *state().font;
|
|
|
|
}
|
2021-09-17 13:06:28 +00:00
|
|
|
void set_font(Font const& font) { state().font = &font; }
|
2018-10-11 21:45:57 +00:00
|
|
|
|
2019-06-07 15:13:23 +00:00
|
|
|
enum class DrawOp {
|
2019-06-05 16:22:11 +00:00
|
|
|
Copy,
|
2020-09-08 04:25:30 +00:00
|
|
|
Xor,
|
|
|
|
Invert
|
2019-06-05 16:22:11 +00:00
|
|
|
};
|
2019-03-09 15:48:02 +00:00
|
|
|
void set_draw_op(DrawOp op) { state().draw_op = op; }
|
|
|
|
DrawOp draw_op() const { return state().draw_op; }
|
2019-01-11 02:52:09 +00:00
|
|
|
|
2021-09-17 13:06:28 +00:00
|
|
|
void add_clip_rect(IntRect const& rect);
|
2019-01-24 22:40:12 +00:00
|
|
|
void clear_clip_rect();
|
2019-02-04 14:37:23 +00:00
|
|
|
|
2021-05-03 14:37:05 +00:00
|
|
|
void translate(int dx, int dy) { translate({ dx, dy }); }
|
2022-12-06 20:27:44 +00:00
|
|
|
void translate(IntPoint delta) { state().translation.translate_by(delta); }
|
2019-03-07 12:13:25 +00:00
|
|
|
|
2022-10-01 12:04:05 +00:00
|
|
|
IntPoint translation() const { return state().translation; }
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
Gfx::Bitmap* target() { return m_target.ptr(); }
|
2019-02-10 13:28:39 +00:00
|
|
|
|
2019-03-09 15:48:02 +00:00
|
|
|
void save() { m_state_stack.append(m_state_stack.last()); }
|
2019-06-05 16:22:11 +00:00
|
|
|
void restore()
|
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(m_state_stack.size() > 1);
|
2019-06-05 16:22:11 +00:00
|
|
|
m_state_stack.take_last();
|
|
|
|
}
|
2019-03-09 15:48:02 +00:00
|
|
|
|
2021-02-16 02:30:47 +00:00
|
|
|
IntRect clip_rect() const { return state().clip_rect; }
|
|
|
|
|
2022-03-19 00:29:22 +00:00
|
|
|
int scale() const { return state().scale; }
|
|
|
|
|
2023-03-08 19:49:00 +00:00
|
|
|
template<typename T, typename TColorOrFunction>
|
|
|
|
ALWAYS_INLINE void draw_scanline_for_fill_path(int y, T x_start, T x_end, TColorOrFunction color)
|
|
|
|
{
|
|
|
|
// Note: This is really an internal function for FillPathImplementation.h to use.
|
|
|
|
// This allows fill path to clip more of the pixels and reduce the number of clipping checks
|
|
|
|
// to the number of scanlines (and allows for a fast fill).
|
|
|
|
|
|
|
|
// Fill path should scale the scanlines before calling this.
|
|
|
|
VERIFY(scale() == 1);
|
|
|
|
|
|
|
|
constexpr bool is_floating_point = IsSameIgnoringCV<T, int>;
|
|
|
|
constexpr bool has_constant_color = IsSameIgnoringCV<TColorOrFunction, Color>;
|
|
|
|
|
|
|
|
int x1 = 0;
|
|
|
|
int x2 = 0;
|
|
|
|
u8 left_subpixel_alpha = 0;
|
|
|
|
u8 right_subpixel_alpha = 0;
|
|
|
|
if constexpr (is_floating_point) {
|
|
|
|
x1 = ceilf(x_start);
|
|
|
|
x2 = floorf(x_end);
|
|
|
|
left_subpixel_alpha = (x1 - x_start) * 255;
|
|
|
|
right_subpixel_alpha = (x_end - x2) * 255;
|
|
|
|
x1 -= left_subpixel_alpha > 0;
|
|
|
|
x2 += right_subpixel_alpha > 0;
|
|
|
|
} else {
|
|
|
|
x1 = x_start;
|
|
|
|
x2 = x_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntRect scanline(x1, y, x2 - x1, 1);
|
|
|
|
scanline = scanline.translated(translation());
|
|
|
|
auto clipped = scanline.intersected(clip_rect());
|
|
|
|
if (clipped.is_empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto get_color = [&](int offset) {
|
|
|
|
if constexpr (has_constant_color) {
|
|
|
|
return color;
|
|
|
|
} else {
|
|
|
|
return color(offset);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if constexpr (is_floating_point) {
|
|
|
|
// Paint left and right subpixels (then remove them from the scanline).
|
|
|
|
auto get_color_with_alpha = [&](int offset, u8 alpha) {
|
|
|
|
auto color_at_offset = get_color(offset);
|
|
|
|
u8 color_alpha = (alpha * color_at_offset.alpha()) / 255;
|
|
|
|
return color_at_offset.with_alpha(color_alpha);
|
|
|
|
};
|
|
|
|
if (clipped.left() == scanline.left() && left_subpixel_alpha)
|
|
|
|
set_physical_pixel(clipped.top_left(), get_color_with_alpha(0, left_subpixel_alpha), true);
|
|
|
|
if (clipped.right() == scanline.right() && right_subpixel_alpha)
|
|
|
|
set_physical_pixel(clipped.top_right(), get_color_with_alpha(scanline.width(), right_subpixel_alpha), true);
|
|
|
|
clipped.shrink(0, right_subpixel_alpha > 0, 0, left_subpixel_alpha > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if constexpr (has_constant_color) {
|
|
|
|
if (color.alpha() == 255) {
|
|
|
|
// Speedy path: Constant color and no alpha blending.
|
|
|
|
fast_u32_fill(m_target->scanline(clipped.y()) + clipped.x(), color.value(), clipped.width());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int x = clipped.x(); x <= clipped.right(); x++) {
|
|
|
|
set_physical_pixel({ x, clipped.y() }, get_color(x - scanline.x()), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-28 16:19:56 +00:00
|
|
|
protected:
|
2023-01-10 01:07:06 +00:00
|
|
|
friend GradientLine;
|
|
|
|
|
2021-09-17 13:06:28 +00:00
|
|
|
IntRect to_physical(IntRect const& r) const { return r.translated(translation()) * scale(); }
|
2022-12-06 20:27:44 +00:00
|
|
|
IntPoint to_physical(IntPoint p) const { return p.translated(translation()) * scale(); }
|
2022-12-06 19:43:46 +00:00
|
|
|
void set_physical_pixel_with_draw_op(u32& pixel, Color);
|
|
|
|
void fill_physical_scanline_with_draw_op(int y, int x, int width, Color color);
|
2021-09-17 13:06:28 +00:00
|
|
|
void fill_rect_with_draw_op(IntRect const&, Color);
|
2022-12-06 20:27:44 +00:00
|
|
|
void blit_with_opacity(IntPoint, Gfx::Bitmap const&, IntRect const& src_rect, float opacity, bool apply_alpha = true);
|
|
|
|
void draw_physical_pixel(IntPoint, Color, int thickness = 1);
|
2022-12-24 14:18:53 +00:00
|
|
|
void set_physical_pixel(IntPoint, Color color, bool blend);
|
2019-01-11 02:52:09 +00:00
|
|
|
|
2019-03-09 15:48:02 +00:00
|
|
|
struct State {
|
2021-09-17 13:06:28 +00:00
|
|
|
Font const* font;
|
2021-05-03 14:37:05 +00:00
|
|
|
IntPoint translation;
|
|
|
|
int scale = 1;
|
2021-01-20 14:59:22 +00:00
|
|
|
IntRect clip_rect;
|
2019-03-09 15:48:02 +00:00
|
|
|
DrawOp draw_op;
|
|
|
|
};
|
|
|
|
|
|
|
|
State& state() { return m_state_stack.last(); }
|
2021-09-17 13:06:28 +00:00
|
|
|
State const& state() const { return m_state_stack.last(); }
|
2019-03-09 15:48:02 +00:00
|
|
|
|
2021-09-17 13:06:28 +00:00
|
|
|
void fill_physical_rect(IntRect const&, Color);
|
2021-05-03 14:37:05 +00:00
|
|
|
|
2020-06-10 08:57:59 +00:00
|
|
|
IntRect m_clip_origin;
|
2020-02-06 10:56:38 +00:00
|
|
|
NonnullRefPtr<Gfx::Bitmap> m_target;
|
2019-04-20 12:02:19 +00:00
|
|
|
Vector<State, 4> m_state_stack;
|
2021-07-25 21:20:11 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Vector<DirectionalRun> split_text_into_directional_runs(Utf8View const&, TextDirection initial_direction);
|
|
|
|
bool text_contains_bidirectional_text(Utf8View const&, TextDirection);
|
|
|
|
template<typename DrawGlyphFunction>
|
2023-01-01 18:42:00 +00:00
|
|
|
void do_draw_text(FloatRect const&, Utf8View const& text, Font const&, TextAlignment, TextElision, TextWrapping, DrawGlyphFunction);
|
2018-10-10 14:49:36 +00:00
|
|
|
};
|
2019-03-09 15:54:41 +00:00
|
|
|
|
|
|
|
class PainterStateSaver {
|
|
|
|
public:
|
2019-04-15 23:01:03 +00:00
|
|
|
explicit PainterStateSaver(Painter&);
|
|
|
|
~PainterStateSaver();
|
2019-03-09 15:54:41 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Painter& m_painter;
|
|
|
|
};
|
2020-02-06 10:56:38 +00:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
DeprecatedString parse_ampersand_string(StringView, Optional<size_t>* underline_offset = nullptr);
|
2021-04-10 23:09:44 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
}
|