소스 검색

Fix underline, and add (back?) overline, line-through values to text-decoration

Michael Ragazzon 6 년 전
부모
커밋
5ef2458abf
4개의 변경된 파일9개의 추가작업 그리고 8개의 파일을 삭제
  1. 3 3
      Source/Core/ElementTextDefault.cpp
  2. 4 4
      Source/Core/FontFaceHandle.cpp
  3. 1 1
      Source/Core/StyleSheetSpecification.cpp
  4. 1 0
      readme.md

+ 3 - 3
Source/Core/ElementTextDefault.cpp

@@ -281,9 +281,6 @@ void ElementTextDefault::AddLine(const Vector2f& line_position, const WString& l
 	lines.push_back(Line(line, baseline_position));
 
 	geometry_dirty = true;
-
-	if (decoration_property != Style::TextDecoration::None)
-		GenerateDecoration(font_face_handle, lines.back());
 }
 
 // Prevents the element from dirtying its document's layout when its text is changed.
@@ -423,6 +420,9 @@ void ElementTextDefault::GenerateGeometry(const FontFaceHandle* font_face_handle
 	line.width = font_face_handle->GenerateString(geometry, line.text, line.position, colour, font_configuration);
 	for (size_t i = 0; i < geometry.size(); ++i)
 		geometry[i].SetHostElement(this);
+
+	if (decoration_property != Style::TextDecoration::None)
+		GenerateDecoration(font_face_handle, line);
 }
 
 // Generates any geometry necessary for rendering a line decoration (underline, strike-through, etc).

+ 4 - 4
Source/Core/FontFaceHandle.cpp

@@ -264,10 +264,10 @@ void FontFaceHandle::GenerateLine(Geometry* geometry, const Vector2f& position,
 	float offset;
 	switch (height)
 	{
-		case Font::UNDERLINE:			offset = -underline_position; break;
-		case Font::OVERLINE:			// where to place? offset = -line_height - underline_position; break;
-		case Font::STRIKE_THROUGH:		// where to place? offset = -line_height * 0.5f; break;
-		default:						return;
+		case Font::UNDERLINE:       offset = -underline_position; break;
+		case Font::OVERLINE:        offset = -underline_position - (float)size; break;
+		case Font::STRIKE_THROUGH:  offset = -0.65f * (float)x_height; break; // or maybe: -underline_position - (float)size * 0.5f
+		default: return;
 	}
 
 	line_vertices.resize(line_vertices.size() + 4);

+ 1 - 1
Source/Core/StyleSheetSpecification.cpp

@@ -340,7 +340,7 @@ void StyleSheetSpecification::RegisterDefaultProperties()
 	RegisterShorthand(ShorthandId::Font, FONT, "font-style, font-weight, font-size, font-family, font-charset", ShorthandType::FallThrough);
 
 	RegisterProperty(PropertyId::TextAlign, TEXT_ALIGN, LEFT, true, true).AddParser("keyword", "left, right, center, justify");
-	RegisterProperty(PropertyId::TextDecoration, TEXT_DECORATION, "none", true, false).AddParser("keyword", "none, underline"/*"none, underline, overline, line-through"*/);
+	RegisterProperty(PropertyId::TextDecoration, TEXT_DECORATION, "none", true, false).AddParser("keyword", "none, underline, overline, line-through");
 	RegisterProperty(PropertyId::TextTransform, TEXT_TRANSFORM, "none", true, true).AddParser("keyword", "none, capitalize, uppercase, lowercase");
 	RegisterProperty(PropertyId::WhiteSpace, WHITE_SPACE, "normal", true, true).AddParser("keyword", "normal, pre, nowrap, pre-wrap, pre-line");
 

+ 1 - 0
readme.md

@@ -253,6 +253,7 @@ Two new CMake options added.
 - `Context::ProcessMouseWheel` now takes a float value for the `wheel_delta` property, thereby enabling continuous/smooth scrolling for input devices with such support. The default scroll length for unity value of `wheel_delta` is now three times the default line-height multiplied by the current dp-ratio.
 - The system interface now has two new functions for setting and getting text to and from the clipboard: `virtual void SystemInterface::SetClipboardText(const Core::WString& text)` and `virtual void SystemInterface::GetClipboardText(Core::WString& text)`.
 - The debugger now has the ability to clear the log. Additionally, the displayed element information updates when the element changes.
+- The `text-decoration` property can now also be used with `overline` and `line-through`.
 
 
 ### Breaking changes