| 
									
										
										
										
											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 17:49:34 +03:30
										 |  |  | #include <AK/ByteString.h>
 | 
					
						
							| 
									
										
										
										
											2023-11-04 21:41:24 +00:00
										 |  |  | #include <AK/CharacterTypes.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-14 00:56:13 +02: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 09:28:38 +02:00
										 |  |  | #include <LibGfx/Font/Font.h>
 | 
					
						
							| 
									
										
										
										
											2023-12-09 23:45:57 +01:00
										 |  |  | #include <LibGfx/FontCascadeList.h>
 | 
					
						
							| 
									
										
										
										
											2022-09-14 00:56:13 +02:00
										 |  |  | #include <LibGfx/Forward.h>
 | 
					
						
							| 
									
										
										
										
											2021-07-25 21:20:11 +00:00
										 |  |  | #include <LibGfx/Rect.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Gfx { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-04 21:41:24 +00:00
										 |  |  | inline bool should_paint_as_space(u32 code_point) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return is_ascii_space(code_point) || code_point == 0xa0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum class IncludeLeftBearing { | 
					
						
							|  |  |  |     Yes, | 
					
						
							|  |  |  |     No | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-05 00:17:04 +01:00
										 |  |  | struct DrawGlyph { | 
					
						
							| 
									
										
										
										
											2023-11-04 21:41:24 +00:00
										 |  |  |     FloatPoint position; | 
					
						
							| 
									
										
										
										
											2024-08-13 17:05:43 +01:00
										 |  |  |     u32 glyph_id; | 
					
						
							| 
									
										
										
										
											2023-12-29 06:10:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void translate_by(FloatPoint const& delta) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         position.translate_by(delta); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-04 21:41:24 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-05 00:17:04 +01:00
										 |  |  | struct DrawEmoji { | 
					
						
							| 
									
										
										
										
											2023-12-02 18:38:05 +01:00
										 |  |  |     FloatPoint position; | 
					
						
							| 
									
										
										
										
											2023-11-05 00:17:04 +01:00
										 |  |  |     Gfx::Bitmap const* emoji; | 
					
						
							| 
									
										
										
										
											2023-12-29 06:10:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void translate_by(FloatPoint const& delta) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         position.translate_by(delta); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-05 00:17:04 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using DrawGlyphOrEmoji = Variant<DrawGlyph, DrawEmoji>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-01 16:37:44 +01:00
										 |  |  | class GlyphRun : public RefCounted<GlyphRun> { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2024-06-29 17:14:23 +02:00
										 |  |  |     GlyphRun(Vector<Gfx::DrawGlyphOrEmoji>&& glyphs, NonnullRefPtr<Font> font) | 
					
						
							| 
									
										
										
										
											2024-03-01 16:37:44 +01:00
										 |  |  |         : m_glyphs(move(glyphs)) | 
					
						
							| 
									
										
										
										
											2024-06-29 17:14:23 +02:00
										 |  |  |         , m_font(move(font)) | 
					
						
							| 
									
										
										
										
											2024-03-01 16:37:44 +01:00
										 |  |  |     { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-29 17:14:23 +02:00
										 |  |  |     [[nodiscard]] Font const& font() const { return m_font; } | 
					
						
							| 
									
										
										
										
											2024-03-01 16:37:44 +01:00
										 |  |  |     [[nodiscard]] Vector<Gfx::DrawGlyphOrEmoji> const& glyphs() const { return m_glyphs; } | 
					
						
							| 
									
										
										
										
											2024-06-29 17:14:23 +02:00
										 |  |  |     [[nodiscard]] Vector<Gfx::DrawGlyphOrEmoji>& glyphs() { return m_glyphs; } | 
					
						
							| 
									
										
										
										
											2024-03-01 16:37:44 +01: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 17:14:23 +02:00
										 |  |  |     NonnullRefPtr<Font> m_font; | 
					
						
							| 
									
										
										
										
											2024-03-01 16:37:44 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-13 17:05:43 +01:00
										 |  |  | void for_each_glyph_position(FloatPoint baseline_start, Utf8View string, Gfx::Font const& font, Function<void(DrawGlyphOrEmoji const&)> callback, IncludeLeftBearing include_left_bearing = IncludeLeftBearing::No, Optional<float&> width = {}); | 
					
						
							| 
									
										
										
										
											2023-11-05 00:17:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-25 21:20:11 +00:00
										 |  |  | } |