Ver código fonte

Change the font effect glyph dimensions behavior, now possible to properly include offsets.

Michael Ragazzon 6 anos atrás
pai
commit
6b6aa40176

+ 1 - 1
Samples/basic/demo/data/demo.rml

@@ -115,7 +115,7 @@ p.title
 {
 	font-size: 35px;
 	color: #b33;
-	font-effect: glow(3px 3px 2px 2px #733); /* 15px 5px  */
+	font-effect: glow(2px 4px 2px 2px #733);
 }
 p.title1
 {

+ 1 - 2
Source/Core/ConvolutionFilter.cpp

@@ -115,9 +115,8 @@ void ConvolutionFilter::Run(byte* destination, const Vector2i destination_dimens
 			case ColorFormat::RGBA8: destination_index = x * 4 + 3; break;
 			case ColorFormat::A8:    destination_index = x; break;
 			}
-				
-			destination[destination_index] = byte(opacity);
 
+			destination[destination_index] = byte(opacity);
 		}
 
 		destination += destination_stride;

+ 2 - 2
Source/Core/FontEffectBlur.cpp

@@ -93,8 +93,8 @@ bool FontEffectBlur::GetGlyphMetrics(Vector2i& origin, Vector2i& dimensions, con
 		origin.x -= width;
 		origin.y -= width;
 
-		dimensions.y += width;
-		dimensions.x += width;
+		dimensions.y += 2 * width;
+		dimensions.x += 2 * width;
 
 		return true;
 	}

+ 2 - 2
Source/Core/FontEffectGlow.cpp

@@ -119,8 +119,8 @@ bool FontEffectGlow::GetGlyphMetrics(Vector2i& origin, Vector2i& dimensions, con
 		origin.x += offset.x - combined_width;
 		origin.y += offset.y - combined_width;
 
-		dimensions.x += combined_width;
-		dimensions.y += combined_width;
+		dimensions.x += 2 * combined_width;
+		dimensions.y += 2 * combined_width;
 
 		return true;
 	}

+ 2 - 2
Source/Core/FontEffectOutline.cpp

@@ -84,8 +84,8 @@ bool FontEffectOutline::GetGlyphMetrics(Vector2i& origin, Vector2i& dimensions,
 		origin.x -= width;
 		origin.y -= width;
 
-		dimensions.x += width;
-		dimensions.y += width;
+		dimensions.x += 2 * width;
+		dimensions.y += 2 * width;
 
 		return true;
 	}

+ 14 - 5
Source/Core/FontEngineDefault/FontFaceLayer.cpp

@@ -77,9 +77,15 @@ bool FontFaceLayer::Generate(const FontFaceHandleDefault* handle, const FontFace
 				Character character = pair.first;
 				const FontGlyph& glyph = pair.second;
 
-				RMLUI_ASSERT(character_boxes.find(character) != character_boxes.end());
+				auto it = character_boxes.find(character);
+				if (it == character_boxes.end())
+				{
+					// This can happen if the layers have been dirtied in FontHandleDefault. We will
+					// probably be regenerated soon, just skip the character for now.
+					continue;
+				}
 
-				TextureBox& box = character_boxes[character];
+				TextureBox& box = it->second;
 
 				Vector2i glyph_origin(Math::RealToInteger(box.origin.x), Math::RealToInteger(box.origin.y));
 				Vector2i glyph_dimensions(Math::RealToInteger(box.dimensions.x), Math::RealToInteger(box.dimensions.y));
@@ -114,12 +120,15 @@ bool FontFaceLayer::Generate(const FontFaceHandleDefault* handle, const FontFace
 			}
 
 			TextureBox box;
-			box.origin = Vector2f((float)(glyph_origin.x + glyph.bearing.x), (float)(glyph_origin.y - glyph.bearing.y));
-			box.dimensions = Vector2f((float)glyph_dimensions.x - glyph_origin.x, (float)glyph_dimensions.y - glyph_origin.y);
+			box.origin = Vector2f(float(glyph_origin.x + glyph.bearing.x), float(glyph_origin.y - glyph.bearing.y));
+			box.dimensions = Vector2f(float(glyph_dimensions.x), float(glyph_dimensions.y));
+			
+			RMLUI_ASSERT(box.dimensions.x >= 0 && box.dimensions.y >= 0);
+
 			character_boxes[character] = box;
 
 			// Add the character's dimensions into the texture layout engine.
-			texture_layout.AddRectangle((int)character, glyph_dimensions - glyph_origin);
+			texture_layout.AddRectangle((int)character, glyph_dimensions);
 		}
 
 		constexpr int max_texture_dimensions = 1024;