mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:42:43 +00:00 
			
		
		
		
	 a2f60911fe
			
		
	
	
		a2f60911fe
		
	
	
	
	
		
			
			This feels like a more fitting name for something that provides the default values for Traits.
		
			
				
	
	
		
			51 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/FlyString.h>
 | |
| #include <AK/HashMap.h>
 | |
| #include <LibGfx/Font/Font.h>
 | |
| #include <LibGfx/Forward.h>
 | |
| #include <LibWeb/Forward.h>
 | |
| 
 | |
| namespace Web {
 | |
| 
 | |
| struct FontSelector {
 | |
|     FlyString family;
 | |
|     float point_size { 0 };
 | |
|     int weight { 0 };
 | |
|     int width { 0 };
 | |
|     int slope { 0 };
 | |
| 
 | |
|     bool operator==(FontSelector const& other) const
 | |
|     {
 | |
|         return family == other.family && point_size == other.point_size && weight == other.weight && width == other.width && slope == other.slope;
 | |
|     }
 | |
| };
 | |
| 
 | |
| class FontCache {
 | |
| public:
 | |
|     FontCache() = default;
 | |
|     RefPtr<Gfx::Font const> get(FontSelector const&) const;
 | |
|     void set(FontSelector const&, NonnullRefPtr<Gfx::Font const>);
 | |
| 
 | |
|     NonnullRefPtr<Gfx::Font const> scaled_font(Gfx::Font const&, float scale_factor);
 | |
| 
 | |
|     void did_load_font(Badge<CSS::StyleComputer>, FlyString const& family_name);
 | |
| 
 | |
| private:
 | |
|     mutable HashMap<FontSelector, NonnullRefPtr<Gfx::Font const>> m_fonts;
 | |
| };
 | |
| 
 | |
| }
 | |
| 
 | |
| namespace AK {
 | |
| template<>
 | |
| struct Traits<Web::FontSelector> : public DefaultTraits<Web::FontSelector> {
 | |
|     static unsigned hash(Web::FontSelector const& key) { return pair_int_hash(pair_int_hash(key.family.hash(), key.weight), key.point_size); }
 | |
| };
 | |
| }
 |