/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, sin-ack * Copyright (c) 2024-2025, Aliaksandr Kalenik * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include namespace Gfx { struct DrawGlyph { FloatPoint position; size_t length_in_code_units { 0 }; float glyph_width { 0.0 }; u32 glyph_id { 0 }; }; class GlyphRun : public AtomicRefCounted { public: enum class TextType { Common, ContextDependent, EndPadding, Ltr, Rtl, }; GlyphRun(Vector&& glyphs, NonnullRefPtr font, TextType text_type, float width, float line_height) : m_glyphs(move(glyphs)) , m_font(move(font)) , m_text_type(text_type) , m_width(width) , m_line_height(line_height) { } [[nodiscard]] Font const& font() const { return m_font; } [[nodiscard]] TextType text_type() const { return m_text_type; } [[nodiscard]] Vector const& glyphs() const { return m_glyphs; } [[nodiscard]] Vector& glyphs() { return m_glyphs; } [[nodiscard]] bool is_empty() const { return m_glyphs.is_empty(); } [[nodiscard]] float width() const { return m_width; } [[nodiscard]] FloatRect bounding_rect() const; private: Vector m_glyphs; NonnullRefPtr m_font; TextType m_text_type; float m_width { 0 }; float m_line_height { 0 }; }; NonnullRefPtr shape_text(FloatPoint baseline_start, float letter_spacing, Utf16View const&, Gfx::Font const& font, GlyphRun::TextType, ShapeFeatures const& features); Vector> shape_text(FloatPoint baseline_start, Utf16View const&, FontCascadeList const&); float measure_text_width(Utf16View const&, Gfx::Font const& font, ShapeFeatures const& features); }