2021-07-25 18:20:11 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
2021-07-25 18:20:11 -03:00
|
|
|
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
2025-04-19 16:36:26 -03:00
|
|
|
* Copyright (c) 2024-2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
2021-07-25 18:20:11 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-02-25 00:07:53 -03:00
|
|
|
#include <AK/AtomicRefCounted.h>
|
2022-09-13 19:56:13 -03:00
|
|
|
#include <AK/Forward.h>
|
2021-07-25 18:20:11 -03:00
|
|
|
#include <AK/Vector.h>
|
2022-04-09 04:28:38 -03:00
|
|
|
#include <LibGfx/Font/Font.h>
|
2025-04-19 16:36:26 -03:00
|
|
|
#include <LibGfx/FontCascadeList.h>
|
2022-09-13 19:56:13 -03:00
|
|
|
#include <LibGfx/Forward.h>
|
2024-11-20 10:37:15 -03:00
|
|
|
#include <LibGfx/Point.h>
|
2021-07-25 18:20:11 -03:00
|
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
|
2023-11-04 20:17:04 -03:00
|
|
|
struct DrawGlyph {
|
2023-11-04 18:41:24 -03:00
|
|
|
FloatPoint position;
|
2025-08-19 14:33:45 -03:00
|
|
|
size_t length_in_code_units { 0 };
|
|
|
|
|
float glyph_width { 0.0 };
|
|
|
|
|
u32 glyph_id { 0 };
|
2023-11-04 18:41:24 -03:00
|
|
|
};
|
|
|
|
|
|
2024-12-04 21:21:45 -03:00
|
|
|
typedef struct ShapeFeature {
|
|
|
|
|
char tag[4];
|
|
|
|
|
u32 value;
|
|
|
|
|
} ShapeFeature;
|
|
|
|
|
|
|
|
|
|
using ShapeFeatures = Vector<ShapeFeature, 4>;
|
|
|
|
|
|
2025-02-25 00:07:53 -03:00
|
|
|
class GlyphRun : public AtomicRefCounted<GlyphRun> {
|
2024-03-01 12:37:44 -03:00
|
|
|
public:
|
2024-08-18 13:58:05 -03:00
|
|
|
enum class TextType {
|
|
|
|
|
Common,
|
|
|
|
|
ContextDependent,
|
|
|
|
|
EndPadding,
|
|
|
|
|
Ltr,
|
|
|
|
|
Rtl,
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-15 18:48:14 -03:00
|
|
|
GlyphRun(Vector<DrawGlyph>&& glyphs, NonnullRefPtr<Font const> font, TextType text_type, float width)
|
2024-03-01 12:37:44 -03:00
|
|
|
: m_glyphs(move(glyphs))
|
2024-06-29 12:14:23 -03:00
|
|
|
, m_font(move(font))
|
2024-08-18 13:58:05 -03:00
|
|
|
, m_text_type(text_type)
|
2024-09-14 14:54:41 -03:00
|
|
|
, m_width(width)
|
2024-03-01 12:37:44 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-29 12:14:23 -03:00
|
|
|
[[nodiscard]] Font const& font() const { return m_font; }
|
2024-08-18 13:58:05 -03:00
|
|
|
[[nodiscard]] TextType text_type() const { return m_text_type; }
|
2024-09-05 20:19:53 -03:00
|
|
|
[[nodiscard]] Vector<DrawGlyph> const& glyphs() const { return m_glyphs; }
|
|
|
|
|
[[nodiscard]] Vector<DrawGlyph>& glyphs() { return m_glyphs; }
|
2024-03-01 12:37:44 -03:00
|
|
|
[[nodiscard]] bool is_empty() const { return m_glyphs.is_empty(); }
|
2024-09-14 14:54:41 -03:00
|
|
|
[[nodiscard]] float width() const { return m_width; }
|
2024-03-01 12:37:44 -03:00
|
|
|
|
|
|
|
|
private:
|
2024-09-05 20:19:53 -03:00
|
|
|
Vector<DrawGlyph> m_glyphs;
|
2025-04-15 18:48:14 -03:00
|
|
|
NonnullRefPtr<Font const> m_font;
|
2024-08-18 13:58:05 -03:00
|
|
|
TextType m_text_type;
|
2024-09-14 14:54:41 -03:00
|
|
|
float m_width { 0 };
|
2024-03-01 12:37:44 -03:00
|
|
|
};
|
|
|
|
|
|
2025-07-25 10:05:18 -03:00
|
|
|
template<typename UnicodeView>
|
|
|
|
|
NonnullRefPtr<GlyphRun> shape_text(FloatPoint baseline_start, float letter_spacing, UnicodeView const& string, Gfx::Font const& font, GlyphRun::TextType, ShapeFeatures const& features);
|
|
|
|
|
|
|
|
|
|
template<typename UnicodeView>
|
|
|
|
|
Vector<NonnullRefPtr<GlyphRun>> shape_text(FloatPoint baseline_start, UnicodeView const& string, FontCascadeList const&);
|
|
|
|
|
|
|
|
|
|
template<typename UnicodeView>
|
|
|
|
|
float measure_text_width(UnicodeView const& string, Gfx::Font const& font, ShapeFeatures const& features);
|
2023-11-04 20:17:04 -03:00
|
|
|
|
2021-07-25 18:20:11 -03:00
|
|
|
}
|