mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 08:32:43 +00:00 
			
		
		
		
	LibWeb: Move font stretch width calc from StyleComputer to StyleValue
This commit is contained in:
		
							parent
							
								
									eb6d41d99e
								
							
						
					
					
						commit
						cc1f7d385c
					
				
					 3 changed files with 62 additions and 55 deletions
				
			
		|  | @ -2079,61 +2079,7 @@ void StyleComputer::compute_font(StyleProperties& style, DOM::Element const* ele | |||
|     auto font_weight = style.property(CSS::PropertyID::FontWeight); | ||||
|     auto font_stretch = style.property(CSS::PropertyID::FontStretch); | ||||
| 
 | ||||
|     int width = Gfx::FontWidth::Normal; | ||||
|     if (font_stretch->is_identifier()) { | ||||
|         switch (static_cast<IdentifierStyleValue const&>(*font_stretch).id()) { | ||||
|         case CSS::ValueID::UltraCondensed: | ||||
|             width = Gfx::FontWidth::UltraCondensed; | ||||
|             break; | ||||
|         case CSS::ValueID::ExtraCondensed: | ||||
|             width = Gfx::FontWidth::ExtraCondensed; | ||||
|             break; | ||||
|         case CSS::ValueID::Condensed: | ||||
|             width = Gfx::FontWidth::Condensed; | ||||
|             break; | ||||
|         case CSS::ValueID::SemiCondensed: | ||||
|             width = Gfx::FontWidth::SemiCondensed; | ||||
|             break; | ||||
|         case CSS::ValueID::Normal: | ||||
|             width = Gfx::FontWidth::Normal; | ||||
|             break; | ||||
|         case CSS::ValueID::SemiExpanded: | ||||
|             width = Gfx::FontWidth::SemiExpanded; | ||||
|             break; | ||||
|         case CSS::ValueID::Expanded: | ||||
|             width = Gfx::FontWidth::Expanded; | ||||
|             break; | ||||
|         case CSS::ValueID::ExtraExpanded: | ||||
|             width = Gfx::FontWidth::ExtraExpanded; | ||||
|             break; | ||||
|         case CSS::ValueID::UltraExpanded: | ||||
|             width = Gfx::FontWidth::UltraExpanded; | ||||
|             break; | ||||
|         default: | ||||
|             break; | ||||
|         } | ||||
|     } else if (font_stretch->is_percentage()) { | ||||
|         float percentage = font_stretch->as_percentage().percentage().value(); | ||||
|         if (percentage <= 50) { | ||||
|             width = Gfx::FontWidth::UltraCondensed; | ||||
|         } else if (percentage <= 62.5f) { | ||||
|             width = Gfx::FontWidth::ExtraCondensed; | ||||
|         } else if (percentage <= 75.0f) { | ||||
|             width = Gfx::FontWidth::Condensed; | ||||
|         } else if (percentage <= 87.5f) { | ||||
|             width = Gfx::FontWidth::SemiCondensed; | ||||
|         } else if (percentage <= 100.0f) { | ||||
|             width = Gfx::FontWidth::Normal; | ||||
|         } else if (percentage <= 112.5f) { | ||||
|             width = Gfx::FontWidth::SemiExpanded; | ||||
|         } else if (percentage <= 125.0f) { | ||||
|             width = Gfx::FontWidth::Expanded; | ||||
|         } else if (percentage <= 150.0f) { | ||||
|             width = Gfx::FontWidth::ExtraExpanded; | ||||
|         } else { | ||||
|             width = Gfx::FontWidth::UltraExpanded; | ||||
|         } | ||||
|     } | ||||
|     int width = font_stretch->to_font_stretch_width(); | ||||
| 
 | ||||
|     auto weight = font_weight->to_font_weight(); | ||||
| 
 | ||||
|  |  | |||
|  | @ -477,4 +477,64 @@ int StyleValue::to_font_slope() const | |||
|     return normal_slope; | ||||
| } | ||||
| 
 | ||||
| int StyleValue::to_font_stretch_width() const | ||||
| { | ||||
|     int width = Gfx::FontWidth::Normal; | ||||
|     if (is_identifier()) { | ||||
|         switch (static_cast<IdentifierStyleValue const&>(*this).id()) { | ||||
|         case CSS::ValueID::UltraCondensed: | ||||
|             width = Gfx::FontWidth::UltraCondensed; | ||||
|             break; | ||||
|         case CSS::ValueID::ExtraCondensed: | ||||
|             width = Gfx::FontWidth::ExtraCondensed; | ||||
|             break; | ||||
|         case CSS::ValueID::Condensed: | ||||
|             width = Gfx::FontWidth::Condensed; | ||||
|             break; | ||||
|         case CSS::ValueID::SemiCondensed: | ||||
|             width = Gfx::FontWidth::SemiCondensed; | ||||
|             break; | ||||
|         case CSS::ValueID::Normal: | ||||
|             width = Gfx::FontWidth::Normal; | ||||
|             break; | ||||
|         case CSS::ValueID::SemiExpanded: | ||||
|             width = Gfx::FontWidth::SemiExpanded; | ||||
|             break; | ||||
|         case CSS::ValueID::Expanded: | ||||
|             width = Gfx::FontWidth::Expanded; | ||||
|             break; | ||||
|         case CSS::ValueID::ExtraExpanded: | ||||
|             width = Gfx::FontWidth::ExtraExpanded; | ||||
|             break; | ||||
|         case CSS::ValueID::UltraExpanded: | ||||
|             width = Gfx::FontWidth::UltraExpanded; | ||||
|             break; | ||||
|         default: | ||||
|             break; | ||||
|         } | ||||
|     } else if (is_percentage()) { | ||||
|         float percentage = as_percentage().percentage().value(); | ||||
|         if (percentage <= 50) { | ||||
|             width = Gfx::FontWidth::UltraCondensed; | ||||
|         } else if (percentage <= 62.5f) { | ||||
|             width = Gfx::FontWidth::ExtraCondensed; | ||||
|         } else if (percentage <= 75.0f) { | ||||
|             width = Gfx::FontWidth::Condensed; | ||||
|         } else if (percentage <= 87.5f) { | ||||
|             width = Gfx::FontWidth::SemiCondensed; | ||||
|         } else if (percentage <= 100.0f) { | ||||
|             width = Gfx::FontWidth::Normal; | ||||
|         } else if (percentage <= 112.5f) { | ||||
|             width = Gfx::FontWidth::SemiExpanded; | ||||
|         } else if (percentage <= 125.0f) { | ||||
|             width = Gfx::FontWidth::Expanded; | ||||
|         } else if (percentage <= 150.0f) { | ||||
|             width = Gfx::FontWidth::ExtraExpanded; | ||||
|         } else { | ||||
|             width = Gfx::FontWidth::UltraExpanded; | ||||
|         } | ||||
|     } | ||||
|     return width; | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -331,6 +331,7 @@ public: | |||
| 
 | ||||
|     [[nodiscard]] int to_font_weight() const; | ||||
|     [[nodiscard]] int to_font_slope() const; | ||||
|     [[nodiscard]] int to_font_stretch_width() const; | ||||
| 
 | ||||
|     virtual bool equals(StyleValue const& other) const = 0; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Bastiaan van der Plaat
						Bastiaan van der Plaat