浏览代码

Fix parsing of some decorators

Michael Ragazzon 6 年之前
父节点
当前提交
40196e5f02
共有 4 个文件被更改,包括 22 次插入18 次删除
  1. 2 2
      Include/RmlUi/Core/StyleSheet.h
  2. 2 2
      Source/Core/ElementStyle.cpp
  3. 16 12
      Source/Core/StyleSheet.cpp
  4. 2 2
      Source/Core/StyleSheetNode.cpp

+ 2 - 2
Include/RmlUi/Core/StyleSheet.h

@@ -95,10 +95,10 @@ public:
 	SharedPtr<Decorator> GetDecorator(const String& name) const;
 
 	/// Parses the decorator property from a string and returns a list of instanced decorators.
-	DecoratorList InstanceDecoratorsFromString(const String& decorator_string_value, const PropertySource* source) const;
+	DecoratorList InstanceDecoratorsFromString(const String& decorator_string_value, const SharedPtr<const PropertySource>& source) const;
 
 	/// Parses the font-effect property from a string and returns a list of instanced font-effects.
-	FontEffectListPtr InstanceFontEffectsFromString(const String& font_effect_string_value, const PropertySource* source) const;
+	FontEffectListPtr InstanceFontEffectsFromString(const String& font_effect_string_value, const SharedPtr<const PropertySource>& source) const;
 
 	/// Get sprite located in any spritesheet within this stylesheet.
 	const Sprite* GetSprite(const String& name) const;

+ 2 - 2
Source/Core/ElementStyle.cpp

@@ -855,7 +855,7 @@ PropertyIdSet ElementStyle::ComputeValues(Style::ComputedValues& values, const S
 				if(auto& style_sheet = element->GetStyleSheet())
 				{
 					String value = p->Get<String>();
-					values.decorator = style_sheet->InstanceDecoratorsFromString(value, p->source.get());
+					values.decorator = style_sheet->InstanceDecoratorsFromString(value, p->source);
 				}
 			}
 			break;
@@ -870,7 +870,7 @@ PropertyIdSet ElementStyle::ComputeValues(Style::ComputedValues& values, const S
 				if (auto & style_sheet = element->GetStyleSheet())
 				{
 					String value = p->Get<String>();
-					values.font_effect = style_sheet->InstanceFontEffectsFromString(value, p->source.get());
+					values.font_effect = style_sheet->InstanceFontEffectsFromString(value, p->source);
 				}
 			}
 			break;

+ 16 - 12
Source/Core/StyleSheet.cpp

@@ -137,7 +137,7 @@ const Sprite* StyleSheet::GetSprite(const String& name) const
 	return spritesheet_list.GetSprite(name);
 }
 
-DecoratorList StyleSheet::InstanceDecoratorsFromString(const String& decorator_string_value, const PropertySource* source) const
+DecoratorList StyleSheet::InstanceDecoratorsFromString(const String& decorator_string_value, const SharedPtr<const PropertySource>& source) const
 {
 	// Decorators are declared as
 	//   decorator: <decorator-value>[, <decorator-value> ...];
@@ -150,7 +150,7 @@ DecoratorList StyleSheet::InstanceDecoratorsFromString(const String& decorator_s
 	if (decorator_string_value.empty() || decorator_string_value == NONE)
 		return decorator_list;
 
-	const char* source_name = (source ? source->path.c_str() : "");
+	const char* source_path = (source ? source->path.c_str() : "");
 	const int source_line_number = (source ? source->line_number : 0);
 
 	// Make sure we don't split inside the parenthesis since they may appear in decorator shorthands.
@@ -173,7 +173,7 @@ DecoratorList StyleSheet::InstanceDecoratorsFromString(const String& decorator_s
 			if (decorator)
 				decorator_list.emplace_back(std::move(decorator));
 			else
-				Log::Message(Log::LT_WARNING, "Decorator name '%s' could not be found in any @decorator rule, declared at %s:%d", decorator_string.c_str(), source_name, source_line_number);
+				Log::Message(Log::LT_WARNING, "Decorator name '%s' could not be found in any @decorator rule, declared at %s:%d", decorator_string.c_str(), source_path, source_line_number);
 		}
 		else
 		{
@@ -184,7 +184,7 @@ DecoratorList StyleSheet::InstanceDecoratorsFromString(const String& decorator_s
 			DecoratorInstancer* instancer = Factory::GetDecoratorInstancer(type);
 			if (!instancer)
 			{
-				Log::Message(Log::LT_WARNING, "Decorator type '%s' not found, declared at %s:%d", type.c_str(), source ? source->path.c_str() : "", source ? source->line_number : -1);
+				Log::Message(Log::LT_WARNING, "Decorator type '%s' not found, declared at %s:%d", type.c_str(), source_path, source_line_number);
 				continue;
 			}
 
@@ -195,12 +195,14 @@ DecoratorList StyleSheet::InstanceDecoratorsFromString(const String& decorator_s
 			PropertyDictionary properties;
 			if (!specification.ParsePropertyDeclaration(properties, "decorator", shorthand))
 			{
-				Log::Message(Log::LT_WARNING, "Could not parse decorator value '%s' at %s:%d", decorator_string.c_str(), source_name, source_line_number);
+				Log::Message(Log::LT_WARNING, "Could not parse decorator value '%s' at %s:%d", decorator_string.c_str(), source_path, source_line_number);
 				continue;
 			}
 
 			// Set unspecified values to their defaults
 			specification.SetPropertyDefaults(properties);
+			
+			properties.SetSourceOfAllProperties(source);
 
 			SharedPtr<Decorator> decorator = instancer->InstanceDecorator(type, properties, DecoratorInstancerInterface(*this));
 
@@ -208,7 +210,7 @@ DecoratorList StyleSheet::InstanceDecoratorsFromString(const String& decorator_s
 				decorator_list.emplace_back(std::move(decorator));
 			else
 			{
-				Log::Message(Log::LT_WARNING, "Decorator '%s' could not be instanced, declared at %s:%d", decorator_string.c_str(), source_name, source_line_number);
+				Log::Message(Log::LT_WARNING, "Decorator '%s' could not be instanced, declared at %s:%d", decorator_string.c_str(), source_path, source_line_number);
 				continue;
 			}
 		}
@@ -217,7 +219,7 @@ DecoratorList StyleSheet::InstanceDecoratorsFromString(const String& decorator_s
 	return decorator_list;
 }
 
-FontEffectListPtr StyleSheet::InstanceFontEffectsFromString(const String& font_effect_string_value, const PropertySource* source) const
+FontEffectListPtr StyleSheet::InstanceFontEffectsFromString(const String& font_effect_string_value, const SharedPtr<const PropertySource>& source) const
 {	
 	// Font-effects are declared as
 	//   font-effect: <font-effect-value>[, <font-effect-value> ...];
@@ -227,7 +229,7 @@ FontEffectListPtr StyleSheet::InstanceFontEffectsFromString(const String& font_e
 	if (font_effect_string_value.empty() || font_effect_string_value == NONE)
 		return nullptr;
 
-	const char* source_name = (source ? source->path.c_str() : "");
+	const char* source_path = (source ? source->path.c_str() : "");
 	const int source_line_number = (source ? source->line_number : 0);
 
 	FontEffectList font_effect_list;
@@ -248,7 +250,7 @@ FontEffectListPtr StyleSheet::InstanceFontEffectsFromString(const String& font_e
 		if (invalid_parenthesis)
 		{
 			// We found no parenthesis, font-effects can only be declared anonymously for now.
-			Log::Message(Log::LT_WARNING, "Invalid syntax for font-effect '%s', declared at %s:%d", font_effect_string.c_str(), source_name, source_line_number);
+			Log::Message(Log::LT_WARNING, "Invalid syntax for font-effect '%s', declared at %s:%d", font_effect_string.c_str(), source_path, source_line_number);
 		}
 		else
 		{
@@ -259,7 +261,7 @@ FontEffectListPtr StyleSheet::InstanceFontEffectsFromString(const String& font_e
 			FontEffectInstancer* instancer = Factory::GetFontEffectInstancer(type);
 			if (!instancer)
 			{
-				Log::Message(Log::LT_WARNING, "Font-effect type '%s' not found, declared at %s:%d", type.c_str(), source_name, source_line_number);
+				Log::Message(Log::LT_WARNING, "Font-effect type '%s' not found, declared at %s:%d", type.c_str(), source_path, source_line_number);
 				continue;
 			}
 
@@ -270,13 +272,15 @@ FontEffectListPtr StyleSheet::InstanceFontEffectsFromString(const String& font_e
 			PropertyDictionary properties;
 			if (!specification.ParsePropertyDeclaration(properties, "font-effect", shorthand))
 			{
-				Log::Message(Log::LT_WARNING, "Could not parse decorator value '%s' at %s:%d", font_effect_string.c_str(), source_name, source_line_number);
+				Log::Message(Log::LT_WARNING, "Could not parse decorator value '%s' at %s:%d", font_effect_string.c_str(), source_path, source_line_number);
 				continue;
 			}
 
 			// Set unspecified values to their defaults
 			specification.SetPropertyDefaults(properties);
 
+			properties.SetSourceOfAllProperties(source);
+
 			SharedPtr<FontEffect> font_effect = instancer->InstanceFontEffect(type, properties);
 			if (font_effect)
 			{
@@ -291,7 +295,7 @@ FontEffectListPtr StyleSheet::InstanceFontEffectsFromString(const String& font_e
 			}
 			else
 			{
-				Log::Message(Log::LT_WARNING, "Font-effect '%s' could not be instanced, declared at %s:%d", font_effect_string.c_str(), source_name, source_line_number);
+				Log::Message(Log::LT_WARNING, "Font-effect '%s' could not be instanced, declared at %s:%d", font_effect_string.c_str(), source_path, source_line_number);
 				continue;
 			}
 		}

+ 2 - 2
Source/Core/StyleSheetNode.cpp

@@ -194,7 +194,7 @@ void StyleSheetNode::BuildIndexAndOptimizeProperties(StyleSheet::NodeIndex& styl
 			if (property->unit == Property::STRING)
 			{
 				const String string_value = property->Get<String>();
-				DecoratorList decorator_list = style_sheet.InstanceDecoratorsFromString(string_value, property->source.get());
+				DecoratorList decorator_list = style_sheet.InstanceDecoratorsFromString(string_value, property->source);
 
 				Property new_property = *property;
 				new_property.value = std::move(decorator_list);
@@ -209,7 +209,7 @@ void StyleSheetNode::BuildIndexAndOptimizeProperties(StyleSheet::NodeIndex& styl
 			if (property->unit == Property::STRING)
 			{
 				const String string_value = property->Get<String>();
-				FontEffectListPtr font_effects = style_sheet.InstanceFontEffectsFromString(string_value, property->source.get());
+				FontEffectListPtr font_effects = style_sheet.InstanceFontEffectsFromString(string_value, property->source);
 
 				Property new_property = *property;
 				new_property.value = std::move(font_effects);