Browse Source

Improve font loading log message and missing font face warning.

Michael Ragazzon 4 years ago
parent
commit
a66b465c4b

+ 6 - 3
Source/Core/FontEngineDefault/FontProvider.cpp

@@ -30,6 +30,7 @@
 #include "FontFace.h"
 #include "FontFamily.h"
 #include "FreeTypeInterface.h"
+#include "../LayoutInlineBoxText.h"
 #include "../../../Include/RmlUi/Core/Core.h"
 #include "../../../Include/RmlUi/Core/FileInterface.h"
 #include "../../../Include/RmlUi/Core/Log.h"
@@ -142,7 +143,7 @@ bool FontProvider::LoadFontFace(const byte* data, int data_size, bool fallback_f
 	
 	if (!ft_face)
 	{
-		Log::Message(Log::LT_ERROR, "Failed to load font face %s (from %s).", font_family.c_str(), source.c_str());
+		Log::Message(Log::LT_ERROR, "Failed to load font face %s from '%s'.", font_family.c_str(), source.c_str());
 		return false;
 	}
 
@@ -151,13 +152,15 @@ bool FontProvider::LoadFontFace(const byte* data, int data_size, bool fallback_f
 		FreeType::GetFaceStyle(ft_face, font_family, style, weight);
 	}
 
+	const String font_face_description = FontFaceDescription(font_family, style, weight);
+
 	if (!AddFace(ft_face, font_family, style, weight, fallback_face, std::move(face_memory)))
 	{
-		Log::Message(Log::LT_ERROR, "Failed to load font face %s (from %s).", font_family.c_str(), source.c_str());
+		Log::Message(Log::LT_ERROR, "Failed to load font face %s from '%s'.", font_face_description.c_str(), source.c_str());
 		return false;
 	}
 
-	Log::Message(Log::LT_INFO, "Loaded font face %s (from %s).", font_family.c_str(), source.c_str());
+	Log::Message(Log::LT_INFO, "Loaded font face %s from '%s'.", font_face_description.c_str(), source.c_str());
 	return true;
 }
 

+ 24 - 4
Source/Core/LayoutInlineBoxText.cpp

@@ -40,6 +40,23 @@
 
 namespace Rml {
 
+String FontFaceDescription(const String& font_family, Style::FontStyle style, Style::FontWeight weight)
+{
+	String font_attributes;
+
+	if (style == Style::FontStyle::Italic)
+		font_attributes += "italic, ";
+	if (weight == Style::FontWeight::Bold)
+		font_attributes += "bold, ";
+
+	if (font_attributes.empty())
+		font_attributes = "regular";
+	else
+		font_attributes.resize(font_attributes.size() - 2);
+
+	return CreateString(font_attributes.size() + font_family.size() + 8, "'%s' [%s]", font_family.c_str(), font_attributes.c_str());
+}
+
 LayoutInlineBoxText::LayoutInlineBoxText(ElementText* element, int _line_begin) : LayoutInlineBox(static_cast<Element*>(element), Box())
 {
 	line_begin = _line_begin;
@@ -160,8 +177,9 @@ void LayoutInlineBoxText::BuildWordBox()
 		height = 0;
 		baseline = 0;
 
+		const ComputedValues& computed = text_element->GetComputedValues();
 		const String font_family_property = text_element->GetProperty<String>("font-family");
-		const String& font_family_computed = text_element->GetComputedValues().font_family;
+		const String& font_family_computed = computed.font_family;
 
 		if (ComputeFontFamily(font_family_property) != font_family_computed)
 		{
@@ -184,11 +202,13 @@ void LayoutInlineBoxText::BuildWordBox()
 		}
 		else
 		{
+			const String font_face_description = FontFaceDescription(font_family_property, computed.font_style, computed.font_weight);
+
 			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(),
+				"No font face defined. Ensure that the specified font face %s has been successfully loaded. "
+				"Please see previous log messages for all successfully loaded fonts. On element %s",
+				font_face_description.c_str(),
 				text_element->GetAddress().c_str()
 			);
 		}

+ 4 - 0
Source/Core/LayoutInlineBoxText.h

@@ -91,5 +91,9 @@ private:
 	bool line_segmented;
 };
 
+
+String FontFaceDescription(const String& font_family, Style::FontStyle style, Style::FontWeight weight);
+
+
 } // namespace Rml
 #endif