Browse Source

Improve error messages on missing font face

Michael Ragazzon 4 years ago
parent
commit
44ef329f28

+ 5 - 0
Source/Core/ComputeProperty.cpp

@@ -173,6 +173,11 @@ float ComputeAngle(const Property& property)
 	return 0.0f;
 }
 
+String ComputeFontFamily(String font_family)
+{
+	return StringUtilities::ToLower(std::move(font_family));
+}
+
 float ComputeFontsize(const Property& property, const Style::ComputedValues& values, const Style::ComputedValues* parent_values, const Style::ComputedValues* document_values, float dp_ratio, Vector2f vp_dimensions)
 {
 	// The calculated value of the font-size property is inherited, so we need to check if this

+ 2 - 0
Source/Core/ComputeProperty.h

@@ -42,6 +42,8 @@ float ComputeAbsoluteLength(const Property& property, float dp_ratio, Vector2f v
 
 float ComputeAngle(const Property& property);
 
+String ComputeFontFamily(String font_family);
+
 float ComputeFontsize(const Property& property, const Style::ComputedValues& values, const Style::ComputedValues* parent_values, const Style::ComputedValues* document_values, float dp_ratio, Vector2f vp_dimensions);
 
 Style::Clip ComputeClip(const Property* property);

+ 1 - 1
Source/Core/ElementStyle.cpp

@@ -811,7 +811,7 @@ PropertyIdSet ElementStyle::ComputeValues(Style::ComputedValues& values, const S
 			break;
 
 		case PropertyId::FontFamily:
-			values.font_family = StringUtilities::ToLower(p->Get<String>());
+			values.font_family = ComputeFontFamily(p->Get<String>());
 			values.font_face_handle = 0;
 			break;
 		case PropertyId::FontStyle:

+ 35 - 1
Source/Core/LayoutInlineBoxText.cpp

@@ -27,6 +27,7 @@
  */
 
 #include "LayoutInlineBoxText.h"
+#include "ComputeProperty.h"
 #include "LayoutEngine.h"
 #include "LayoutLineBox.h"
 #include "../../Include/RmlUi/Core/Core.h"
@@ -158,7 +159,40 @@ void LayoutInlineBoxText::BuildWordBox()
 	{
 		height = 0;
 		baseline = 0;
-		Log::Message(Log::LT_WARNING, "No font face defined on element %s. Please specify a font-family in your RCSS, otherwise make sure Context::Update is run after new elements are constructed, before Context::Render.", text_element->GetAddress().c_str());
+
+		const String font_family_property = text_element->GetProperty<String>("font-family");
+		const String& font_family_computed = text_element->GetComputedValues().font_family;
+
+		if (ComputeFontFamily(font_family_property) != font_family_computed)
+		{
+			Log::Message(
+				Log::LT_WARNING,
+				"No font face defined. Mismatch between specified font family property '%s' and computed value '%s'. "
+				"Make sure Context::Update is run after new elements are constructed, before Context::Render. On element %s",
+				font_family_property.c_str(),
+				font_family_computed.c_str(),
+				text_element->GetAddress().c_str()
+			);
+		}
+		else if (font_family_property.empty())
+		{
+			Log::Message(
+				Log::LT_WARNING,
+				"No font face defined. Missing 'font-family' property, please add it to your RCSS. On element %s",
+				text_element->GetAddress().c_str()
+			);
+		}
+		else
+		{
+			Log::Message(
+				Log::LT_WARNING,
+				"No font face defined. Ensure that the specified font family '%s' is correct and has been successfully loaded. "
+				"Please see previous log messages for all successfully loaded fonts, their font family names are logged when they are loaded. On element %s",
+				font_family_property.c_str(),
+				text_element->GetAddress().c_str()
+			);
+		}
+
 		return;
 	}