浏览代码

Don't load default glyphs for fallback fonts

Michael Ragazzon 3 年之前
父节点
当前提交
2b12e0ad83

+ 3 - 2
Source/Core/FontEngineDefault/FontFace.cpp

@@ -65,7 +65,8 @@ Style::FontWeight FontFace::GetWeight() const
 	return weight;
 	return weight;
 }
 }
 
 
-FontFaceHandleDefault* FontFace::GetHandle(int size) {
+FontFaceHandleDefault* FontFace::GetHandle(int size, bool load_default_glyphs)
+{
 	auto it = handles.find(size);
 	auto it = handles.find(size);
 	if (it != handles.end())
 	if (it != handles.end())
 		return it->second.get();
 		return it->second.get();
@@ -79,7 +80,7 @@ FontFaceHandleDefault* FontFace::GetHandle(int size) {
 
 
 	// Construct and initialise the new handle.
 	// Construct and initialise the new handle.
 	auto handle = MakeUnique<FontFaceHandleDefault>();
 	auto handle = MakeUnique<FontFaceHandleDefault>();
-	if (!handle->Initialize(face, size))
+	if (!handle->Initialize(face, size, load_default_glyphs))
 	{
 	{
 		handles[size] = nullptr;
 		handles[size] = nullptr;
 		return nullptr;
 		return nullptr;

+ 2 - 1
Source/Core/FontEngineDefault/FontFace.h

@@ -51,8 +51,9 @@ public:
 
 
 	/// Returns a handle for positioning and rendering this face at the given size.
 	/// Returns a handle for positioning and rendering this face at the given size.
 	/// @param[in] size The size of the desired handle, in points.
 	/// @param[in] size The size of the desired handle, in points.
+	/// @param[in] load_default_glyphs True to load the default set of glyph (ASCII range).
 	/// @return The font handle.
 	/// @return The font handle.
-	FontFaceHandleDefault* GetHandle(int size);
+	FontFaceHandleDefault* GetHandle(int size, bool load_default_glyphs);
 
 
 private:
 private:
 	Style::FontStyle style;
 	Style::FontStyle style;

+ 2 - 4
Source/Core/FontEngineDefault/FontFaceHandleDefault.cpp

@@ -52,16 +52,14 @@ FontFaceHandleDefault::~FontFaceHandleDefault()
 	layers.clear();
 	layers.clear();
 }
 }
 
 
-bool FontFaceHandleDefault::Initialize(FontFaceHandleFreetype face, int font_size)
+bool FontFaceHandleDefault::Initialize(FontFaceHandleFreetype face, int font_size, bool load_default_glyphs)
 {
 {
 	ft_face = face;
 	ft_face = face;
 
 
 	RMLUI_ASSERTMSG(layer_configurations.empty(), "Initialize must only be called once.");
 	RMLUI_ASSERTMSG(layer_configurations.empty(), "Initialize must only be called once.");
 
 
-	if (!FreeType::InitialiseFaceHandle(ft_face, font_size, glyphs, metrics))
-	{
+	if (!FreeType::InitialiseFaceHandle(ft_face, font_size, glyphs, metrics, load_default_glyphs))
 		return false;
 		return false;
-	}
 
 
 	has_kerning = FreeType::HasKerning(ft_face);
 	has_kerning = FreeType::HasKerning(ft_face);
 	FillKerningPairCache();
 	FillKerningPairCache();

+ 1 - 1
Source/Core/FontEngineDefault/FontFaceHandleDefault.h

@@ -51,7 +51,7 @@ public:
 	FontFaceHandleDefault();
 	FontFaceHandleDefault();
 	~FontFaceHandleDefault();
 	~FontFaceHandleDefault();
 
 
-	bool Initialize(FontFaceHandleFreetype face, int font_size);
+	bool Initialize(FontFaceHandleFreetype face, int font_size, bool load_default_glyphs);
 
 
 	/// Returns the point size of this font face.
 	/// Returns the point size of this font face.
 	int GetSize() const;
 	int GetSize() const;

+ 1 - 1
Source/Core/FontEngineDefault/FontFamily.cpp

@@ -56,7 +56,7 @@ FontFaceHandleDefault* FontFamily::GetFaceHandle(Style::FontStyle style, Style::
 	if (matching_face == nullptr)
 	if (matching_face == nullptr)
 		return nullptr;
 		return nullptr;
 
 
-	return matching_face->GetHandle(size);
+	return matching_face->GetHandle(size, false);
 }
 }
 
 
 
 

+ 1 - 1
Source/Core/FontEngineDefault/FontProvider.cpp

@@ -97,7 +97,7 @@ FontFaceHandleDefault* FontProvider::GetFallbackFontFace(int index, int font_siz
 	auto& faces = FontProvider::Get().fallback_font_faces;
 	auto& faces = FontProvider::Get().fallback_font_faces;
 
 
 	if (index >= 0 && index < (int)faces.size())
 	if (index >= 0 && index < (int)faces.size())
-		return faces[index]->GetHandle(font_size);
+		return faces[index]->GetHandle(font_size, true);
 
 
 	return nullptr;
 	return nullptr;
 }
 }

+ 13 - 10
Source/Core/FontEngineDefault/FreeTypeInterface.cpp

@@ -39,7 +39,7 @@ namespace Rml {
 static FT_Library ft_library = nullptr;
 static FT_Library ft_library = nullptr;
 
 
 static bool BuildGlyph(FT_Face ft_face, Character character, FontGlyphMap& glyphs, float bitmap_scaling_factor);
 static bool BuildGlyph(FT_Face ft_face, Character character, FontGlyphMap& glyphs, float bitmap_scaling_factor);
-static void BuildGlyphMap(FT_Face ft_face, int size, FontGlyphMap& glyphs, float bitmap_scaling_factor);
+static void BuildGlyphMap(FT_Face ft_face, int size, FontGlyphMap& glyphs, float bitmap_scaling_factor, bool load_default_glyphs);
 static void GenerateMetrics(FT_Face ft_face, FontMetrics& metrics, float bitmap_scaling_factor);
 static void GenerateMetrics(FT_Face ft_face, FontMetrics& metrics, float bitmap_scaling_factor);
 static bool SetFontSize(FT_Face ft_face, int font_size, float& out_bitmap_scaling_factor);
 static bool SetFontSize(FT_Face ft_face, int font_size, float& out_bitmap_scaling_factor);
 static void BitmapDownscale(byte* bitmap_new, int new_width, int new_height, const byte* bitmap_source, int width, int height, int pitch,
 static void BitmapDownscale(byte* bitmap_new, int new_width, int new_height, const byte* bitmap_source, int width, int height, int pitch,
@@ -115,7 +115,7 @@ void FreeType::GetFaceStyle(FontFaceHandleFreetype in_face, String& font_family,
 }
 }
 
 
 // Initialises the handle so it is able to render text.
 // Initialises the handle so it is able to render text.
-bool FreeType::InitialiseFaceHandle(FontFaceHandleFreetype face, int font_size, FontGlyphMap& glyphs, FontMetrics& metrics)
+bool FreeType::InitialiseFaceHandle(FontFaceHandleFreetype face, int font_size, FontGlyphMap& glyphs, FontMetrics& metrics, bool load_default_glyphs)
 {
 {
 	FT_Face ft_face = (FT_Face)face;
 	FT_Face ft_face = (FT_Face)face;
 
 
@@ -126,7 +126,7 @@ bool FreeType::InitialiseFaceHandle(FontFaceHandleFreetype face, int font_size,
 		return false;
 		return false;
 
 
 	// Construct the initial list of glyphs.
 	// Construct the initial list of glyphs.
-	BuildGlyphMap(ft_face, font_size, glyphs, bitmap_scaling_factor);
+	BuildGlyphMap(ft_face, font_size, glyphs, bitmap_scaling_factor, load_default_glyphs);
 
 
 	// Generate the metrics for the handle.
 	// Generate the metrics for the handle.
 	GenerateMetrics(ft_face, metrics, bitmap_scaling_factor);
 	GenerateMetrics(ft_face, metrics, bitmap_scaling_factor);
@@ -194,16 +194,19 @@ bool FreeType::HasKerning(FontFaceHandleFreetype face)
 
 
 
 
 
 
-static void BuildGlyphMap(FT_Face ft_face, int size, FontGlyphMap& glyphs, const float bitmap_scaling_factor)
+static void BuildGlyphMap(FT_Face ft_face, int size, FontGlyphMap& glyphs, const float bitmap_scaling_factor, const bool load_default_glyphs)
 {
 {
-	glyphs.reserve(128);
+	if (load_default_glyphs)
+	{
+		glyphs.reserve(128);
 
 
-	// Add the ASCII characters now. Other characters are added later as needed.
-	FT_ULong code_min = 32;
-	FT_ULong code_max = 126;
+		// Add the ASCII characters now. Other characters are added later as needed.
+		FT_ULong code_min = 32;
+		FT_ULong code_max = 126;
 
 
-	for (FT_ULong character_code = code_min; character_code <= code_max; ++character_code)
-		BuildGlyph(ft_face, (Character)character_code, glyphs, bitmap_scaling_factor);
+		for (FT_ULong character_code = code_min; character_code <= code_max; ++character_code)
+			BuildGlyph(ft_face, (Character)character_code, glyphs, bitmap_scaling_factor);
+	}
 
 
 	// Add a replacement character for rendering unknown characters.
 	// Add a replacement character for rendering unknown characters.
 	Character replacement_character = Character::Replacement;
 	Character replacement_character = Character::Replacement;

+ 1 - 1
Source/Core/FontEngineDefault/FreeTypeInterface.h

@@ -50,7 +50,7 @@ bool ReleaseFace(FontFaceHandleFreetype face);
 void GetFaceStyle(FontFaceHandleFreetype face, String& font_family, Style::FontStyle& style, Style::FontWeight& weight);
 void GetFaceStyle(FontFaceHandleFreetype face, String& font_family, Style::FontStyle& style, Style::FontWeight& weight);
 
 
 // Initializes a face for a given font size. Glyphs are filled with the ASCII subset, and the font face metrics are set.
 // Initializes a face for a given font size. Glyphs are filled with the ASCII subset, and the font face metrics are set.
-bool InitialiseFaceHandle(FontFaceHandleFreetype face, int font_size, FontGlyphMap& glyphs, FontMetrics& metrics);
+bool InitialiseFaceHandle(FontFaceHandleFreetype face, int font_size, FontGlyphMap& glyphs, FontMetrics& metrics, bool load_default_glyphs);
 
 
 // Build a new glyph representing the given code point and append to 'glyphs'.
 // Build a new glyph representing the given code point and append to 'glyphs'.
 bool AppendGlyph(FontFaceHandleFreetype face, int font_size, Character character, FontGlyphMap& glyphs);
 bool AppendGlyph(FontFaceHandleFreetype face, int font_size, Character character, FontGlyphMap& glyphs);