2021-07-25 21:20:11 +00:00
|
|
|
/*
|
2024-10-04 11:19:50 +00:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2021-07-25 21:20:11 +00:00
|
|
|
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-09-13 22:56:13 +00:00
|
|
|
#include <AK/Forward.h>
|
2021-07-25 21:20:11 +00:00
|
|
|
#include <AK/Utf8View.h>
|
|
|
|
#include <AK/Vector.h>
|
2022-04-09 07:28:38 +00:00
|
|
|
#include <LibGfx/Font/Font.h>
|
2022-09-13 22:56:13 +00:00
|
|
|
#include <LibGfx/Forward.h>
|
2024-11-20 13:37:15 +00:00
|
|
|
#include <LibGfx/Point.h>
|
2021-07-25 21:20:11 +00:00
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
2023-11-04 23:17:04 +00:00
|
|
|
struct DrawGlyph {
|
2023-11-04 21:41:24 +00:00
|
|
|
FloatPoint position;
|
2024-08-13 16:05:43 +00:00
|
|
|
u32 glyph_id;
|
2023-12-29 05:10:32 +00:00
|
|
|
|
|
|
|
void translate_by(FloatPoint const& delta)
|
|
|
|
{
|
|
|
|
position.translate_by(delta);
|
|
|
|
}
|
2023-11-04 21:41:24 +00:00
|
|
|
};
|
|
|
|
|
2024-03-01 15:37:44 +00:00
|
|
|
class GlyphRun : public RefCounted<GlyphRun> {
|
|
|
|
public:
|
2024-08-18 16:58:05 +00:00
|
|
|
enum class TextType {
|
|
|
|
Common,
|
|
|
|
ContextDependent,
|
|
|
|
EndPadding,
|
|
|
|
Ltr,
|
|
|
|
Rtl,
|
|
|
|
};
|
|
|
|
|
2024-09-14 17:54:41 +00:00
|
|
|
GlyphRun(Vector<DrawGlyph>&& glyphs, NonnullRefPtr<Font> font, TextType text_type, float width)
|
2024-03-01 15:37:44 +00:00
|
|
|
: m_glyphs(move(glyphs))
|
2024-06-29 15:14:23 +00:00
|
|
|
, m_font(move(font))
|
2024-08-18 16:58:05 +00:00
|
|
|
, m_text_type(text_type)
|
2024-09-14 17:54:41 +00:00
|
|
|
, m_width(width)
|
2024-03-01 15:37:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-06-29 15:14:23 +00:00
|
|
|
[[nodiscard]] Font const& font() const { return m_font; }
|
2024-08-18 16:58:05 +00:00
|
|
|
[[nodiscard]] TextType text_type() const { return m_text_type; }
|
2024-09-05 23:19:53 +00:00
|
|
|
[[nodiscard]] Vector<DrawGlyph> const& glyphs() const { return m_glyphs; }
|
|
|
|
[[nodiscard]] Vector<DrawGlyph>& glyphs() { return m_glyphs; }
|
2024-03-01 15:37:44 +00:00
|
|
|
[[nodiscard]] bool is_empty() const { return m_glyphs.is_empty(); }
|
2024-09-14 17:54:41 +00:00
|
|
|
[[nodiscard]] float width() const { return m_width; }
|
2024-03-01 15:37:44 +00:00
|
|
|
|
2024-09-05 23:19:53 +00:00
|
|
|
void append(DrawGlyph glyph) { m_glyphs.append(glyph); }
|
2024-03-01 15:37:44 +00:00
|
|
|
|
|
|
|
private:
|
2024-09-05 23:19:53 +00:00
|
|
|
Vector<DrawGlyph> m_glyphs;
|
2024-06-29 15:14:23 +00:00
|
|
|
NonnullRefPtr<Font> m_font;
|
2024-08-18 16:58:05 +00:00
|
|
|
TextType m_text_type;
|
2024-09-14 17:54:41 +00:00
|
|
|
float m_width { 0 };
|
2024-03-01 15:37:44 +00:00
|
|
|
};
|
|
|
|
|
2024-11-05 07:11:34 +00:00
|
|
|
RefPtr<GlyphRun> shape_text(FloatPoint baseline_start, float letter_spacing, Utf8View string, Gfx::Font const& font, GlyphRun::TextType);
|
2024-09-03 19:12:29 +00:00
|
|
|
float measure_text_width(Utf8View const& string, Gfx::Font const& font);
|
2023-11-04 23:17:04 +00:00
|
|
|
|
2021-07-25 21:20:11 +00:00
|
|
|
}
|