| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibGfx/FontCascadeList.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Gfx { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:48:14 -06:00
										 |  |  | void FontCascadeList::add(NonnullRefPtr<Font const> font) | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     m_fonts.append({ move(font), {} }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-15 15:48:14 -06:00
										 |  |  | void FontCascadeList::add(NonnullRefPtr<Font const> font, Vector<UnicodeRange> unicode_ranges) | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-07-15 00:16:06 +02:00
										 |  |  |     if (unicode_ranges.is_empty()) { | 
					
						
							|  |  |  |         m_fonts.append({ move(font), {} }); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-07-14 17:59:58 +02:00
										 |  |  |     u32 lowest_code_point = 0xFFFFFFFF; | 
					
						
							|  |  |  |     u32 highest_code_point = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto& range : unicode_ranges) { | 
					
						
							|  |  |  |         lowest_code_point = min(lowest_code_point, range.min_code_point()); | 
					
						
							|  |  |  |         highest_code_point = max(highest_code_point, range.max_code_point()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_fonts.append({ move(font), | 
					
						
							|  |  |  |         Entry::RangeData { | 
					
						
							|  |  |  |             { lowest_code_point, highest_code_point }, | 
					
						
							|  |  |  |             move(unicode_ranges), | 
					
						
							|  |  |  |         } }); | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FontCascadeList::extend(FontCascadeList const& other) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2025-06-17 12:32:31 +02:00
										 |  |  |     m_fonts.extend(other.m_fonts); | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Gfx::Font const& FontCascadeList::font_for_code_point(u32 code_point) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     for (auto const& entry : m_fonts) { | 
					
						
							| 
									
										
										
										
											2025-07-14 17:59:58 +02:00
										 |  |  |         if (entry.range_data.has_value()) { | 
					
						
							|  |  |  |             if (!entry.range_data->enclosing_range.contains(code_point)) | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             for (auto const& range : entry.range_data->unicode_ranges) { | 
					
						
							| 
									
										
										
										
											2024-09-05 22:33:36 +02:00
										 |  |  |                 if (range.contains(code_point) && entry.font->contains_glyph(code_point)) | 
					
						
							|  |  |  |                     return entry.font; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else if (entry.font->contains_glyph(code_point)) { | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  |             return entry.font; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-09-05 22:33:36 +02:00
										 |  |  |     return *m_last_resort_font; | 
					
						
							| 
									
										
										
										
											2023-12-09 23:42:02 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool FontCascadeList::equals(FontCascadeList const& other) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_fonts.size() != other.m_fonts.size()) | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     for (size_t i = 0; i < m_fonts.size(); ++i) { | 
					
						
							|  |  |  |         if (m_fonts[i].font != other.m_fonts[i].font) | 
					
						
							|  |  |  |             return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |