/* * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2021, sin-ack * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace Gfx { struct DrawGlyph { FloatPoint position; u32 glyph_id; void translate_by(FloatPoint const& delta) { position.translate_by(delta); } }; struct DrawEmoji { FloatPoint position; Gfx::Bitmap const* emoji; void translate_by(FloatPoint const& delta) { position.translate_by(delta); } }; using DrawGlyphOrEmoji = Variant; class GlyphRun : public RefCounted { public: enum class TextType { Common, ContextDependent, EndPadding, Ltr, Rtl, }; GlyphRun(Vector&& glyphs, NonnullRefPtr font, TextType text_type) : m_glyphs(move(glyphs)) , m_font(move(font)) , m_text_type(text_type) { } [[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(); } void append(Gfx::DrawGlyphOrEmoji glyph) { m_glyphs.append(glyph); } private: Vector m_glyphs; NonnullRefPtr m_font; TextType m_text_type; }; void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, Gfx::Font const& font, Function callback, Optional width = {}); }