2021-07-25 21:20:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
#include <AK/ByteString.h>
|
2023-11-04 21:41:24 +00:00
|
|
|
#include <AK/CharacterTypes.h>
|
2022-09-13 22:56:13 +00:00
|
|
|
#include <AK/Forward.h>
|
2021-07-25 21:20:11 +00:00
|
|
|
#include <AK/Utf32View.h>
|
|
|
|
#include <AK/Utf8View.h>
|
|
|
|
#include <AK/Vector.h>
|
2022-04-09 07:28:38 +00:00
|
|
|
#include <LibGfx/Font/Font.h>
|
2023-12-09 22:45:57 +00:00
|
|
|
#include <LibGfx/FontCascadeList.h>
|
2022-09-13 22:56:13 +00:00
|
|
|
#include <LibGfx/Forward.h>
|
2021-07-25 21:20:11 +00:00
|
|
|
#include <LibGfx/Rect.h>
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2023-11-04 23:17:04 +00:00
|
|
|
struct DrawEmoji {
|
2023-12-02 17:38:05 +00:00
|
|
|
FloatPoint position;
|
2023-11-04 23:17:04 +00:00
|
|
|
Gfx::Bitmap const* emoji;
|
2023-12-29 05:10:32 +00:00
|
|
|
|
|
|
|
void translate_by(FloatPoint const& delta)
|
|
|
|
{
|
|
|
|
position.translate_by(delta);
|
|
|
|
}
|
2023-11-04 23:17:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using DrawGlyphOrEmoji = Variant<DrawGlyph, DrawEmoji>;
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
GlyphRun(Vector<Gfx::DrawGlyphOrEmoji>&& glyphs, NonnullRefPtr<Font> font, TextType text_type)
|
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-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-03-01 15:37:44 +00:00
|
|
|
[[nodiscard]] Vector<Gfx::DrawGlyphOrEmoji> const& glyphs() const { return m_glyphs; }
|
2024-06-29 15:14:23 +00:00
|
|
|
[[nodiscard]] Vector<Gfx::DrawGlyphOrEmoji>& glyphs() { return m_glyphs; }
|
2024-03-01 15:37:44 +00:00
|
|
|
[[nodiscard]] bool is_empty() const { return m_glyphs.is_empty(); }
|
|
|
|
|
|
|
|
void append(Gfx::DrawGlyphOrEmoji glyph) { m_glyphs.append(glyph); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Vector<Gfx::DrawGlyphOrEmoji> 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-03-01 15:37:44 +00:00
|
|
|
};
|
|
|
|
|
2024-08-19 16:05:29 +00:00
|
|
|
void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, Gfx::Font const& font, Function<void(DrawGlyphOrEmoji const&)> callback, Optional<float&> width = {});
|
2023-11-04 23:17:04 +00:00
|
|
|
|
2021-07-25 21:20:11 +00:00
|
|
|
}
|