Browse Source

Shared string for font family

Michael Ragazzon 6 years ago
parent
commit
e91ea9c63b

+ 1 - 1
Include/Rocket/Core/ComputedValues.h

@@ -168,7 +168,7 @@ struct ComputedValues
 	Colourb image_color = Colourb(255, 255, 255);
 	float opacity = 1;
 
-	String font_family;
+	SharedString font_family;
 	String font_charset; // empty is same as "U+0020-007E"
 	FontStyle font_style = FontStyle::Normal;
 	FontWeight font_weight = FontWeight::Normal;

+ 1 - 1
Include/Rocket/Core/Context.h

@@ -237,7 +237,7 @@ private:
 
 	ContextInstancer* instancer;
 
-	typedef SmallUnorderedSet< ElementReference > ElementSet;
+	typedef SmallOrderedSet< ElementReference > ElementSet;
 	typedef std::vector< ElementReference > ElementList;
 	// Set of elements that are currently in hover state.
 	ElementSet hover_chain;

+ 4 - 3
Include/Rocket/Core/Types.h

@@ -110,10 +110,11 @@ using UnorderedMap = robin_hood::unordered_flat_map< Key, Value >;
 template < typename Key, typename Value>
 using SmallUnorderedMap = chobo::flat_map< Key, Value >;
 template < typename T >
+using SmallOrderedSet = chobo::flat_set< T >;
+template < typename T >
 using SmallUnorderedSet = chobo::flat_set< T >;
-// Note: Strictly speaking, the chobo maps are ordered, but we may want to replace
-// them with unordered containers later. If we really need an ordered container 
-// for some type, we should create an alias.
+// Note: Right now ordered and unordered set use the same container, but we may
+// want to change this later so use ordered when a sorted container is needed.
 
 // Container types for some common lists
 typedef std::vector< Element* > ElementList;

+ 1 - 1
Source/Core/ElementStyle.cpp

@@ -916,7 +916,7 @@ void ElementStyle::ComputeValues(Style::ComputedValues& values, const Style::Com
 			values.opacity = p->Get<float>();
 
 		else if (name == FONT_FAMILY)
-			values.font_family = ToLower(p->Get<String>());
+			values.font_family = std::make_shared<String>(ToLower(p->Get<String>()));
 		else if (name == FONT_CHARSET)
 			values.font_charset = p->Get<String>();
 		else if (name == FONT_STYLE)

+ 3 - 1
Source/Core/ElementUtilities.cpp

@@ -115,13 +115,15 @@ void ElementUtilities::GetElementsByClassName(ElementList& elements, Element* ro
 // Returns the element's font face.
 FontFaceHandle* ElementUtilities::GetFontFaceHandle(const Style::ComputedValues& computed_values)
 {
+	static const String default_family;
 	static const String default_charset = "U+0020-007E";
 
+	const String& family = (computed_values.font_family ? *computed_values.font_family : default_family);
 	const String& charset = (computed_values.font_charset.empty() ? default_charset : computed_values.font_charset);
 	int font_size = (int)computed_values.font_size;
 
 	// TODO Synchronize enums
-	FontFaceHandle* font = FontDatabase::GetFontFaceHandle(computed_values.font_family, charset, (Font::Style)computed_values.font_style, (Font::Weight)computed_values.font_weight, font_size);
+	FontFaceHandle* font = FontDatabase::GetFontFaceHandle(family, charset, (Font::Style)computed_values.font_style, (Font::Weight)computed_values.font_weight, font_size);
 	return font;
 }