mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:42:44 +00:00 
			
		
		
		
	LibWeb: Implement font-fallback
If the font-family property is set to a StyleValueList, we now iterate through it, looking up each font in turn until one is found. StyleResolver no longer needs to handle FontFamily specifically, which is a nice bonus. Serenity's current dependence on bitmap fonts leads to some weirdness here - for example, the `if (!found_font)` path can trigger even if a generic font family like "sans-serif" is used, since our default sans-serif font might not be available in the desired size or weight. The `monospace` variable only exists for that reason. This is not a complete solution, by a long way! Serenity's font support is still quite basic, so more work needs to be done there before we can start implementing the spec's font-matching algorithm. But this is still an improvement. :^)
This commit is contained in:
		
							parent
							
								
									ceece1c75e
								
							
						
					
					
						commit
						b64b97ef88
					
				
					 2 changed files with 59 additions and 42 deletions
				
			
		|  | @ -442,7 +442,7 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope | |||
|         if (value.is_font()) { | ||||
|             auto& font_shorthand = static_cast<CSS::FontStyleValue const&>(value); | ||||
|             style.set_property(CSS::PropertyID::FontSize, font_shorthand.font_size()); | ||||
|             set_property_expanding_shorthands(style, CSS::PropertyID::FontFamily, *font_shorthand.font_families(), document); | ||||
|             style.set_property(CSS::PropertyID::FontFamily, font_shorthand.font_families()); | ||||
|             style.set_property(CSS::PropertyID::FontStyle, font_shorthand.font_style()); | ||||
|             style.set_property(CSS::PropertyID::FontWeight, font_shorthand.font_weight()); | ||||
|             style.set_property(CSS::PropertyID::LineHeight, font_shorthand.line_height()); | ||||
|  | @ -451,7 +451,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope | |||
|         } | ||||
|         if (value.is_builtin()) { | ||||
|             style.set_property(CSS::PropertyID::FontSize, value); | ||||
|             // FIXME: Support multiple font-families
 | ||||
|             style.set_property(CSS::PropertyID::FontFamily, value); | ||||
|             style.set_property(CSS::PropertyID::FontStyle, value); | ||||
|             style.set_property(CSS::PropertyID::FontWeight, value); | ||||
|  | @ -462,22 +461,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope | |||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     if (property_id == CSS::PropertyID::FontFamily) { | ||||
|         if (value.is_value_list()) { | ||||
|             auto& values_list = static_cast<StyleValueList const&>(value).values(); | ||||
|             // FIXME: Support multiple font-families
 | ||||
|             if (!values_list.is_empty()) { | ||||
|                 style.set_property(CSS::PropertyID::FontFamily, values_list.first()); | ||||
|             } | ||||
|             return; | ||||
|         } | ||||
|         if (value.is_builtin() || value.is_string() || value.is_identifier()) { | ||||
|             style.set_property(CSS::PropertyID::FontFamily, value); | ||||
|             return; | ||||
|         } | ||||
|         return; | ||||
|     } | ||||
| 
 | ||||
|     if (property_id == CSS::PropertyID::Flex) { | ||||
|         if (value.is_flex()) { | ||||
|             auto& flex = static_cast<CSS::FlexStyleValue const&>(value); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sam Atkins
						Sam Atkins