2
0
Эх сурвалжийг харах

Reorganize and clean up font effects

Michael Ragazzon 6 жил өмнө
parent
commit
86c17d46c8

+ 0 - 4
CMake/FileList.cmake

@@ -33,9 +33,7 @@ set(Core_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/EventSpecification.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FileInterfaceDefault.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectOutline.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectOutlineInstancer.h
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadow.h
-    ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadowInstancer.h
     ${PROJECT_SOURCE_DIR}/Source/Core/IdNameMap.h
     ${PROJECT_SOURCE_DIR}/Source/Core/LayoutBlockBox.h
     ${PROJECT_SOURCE_DIR}/Source/Core/LayoutBlockBoxSpace.h
@@ -233,9 +231,7 @@ set(Core_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffect.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectInstancer.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectOutline.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectOutlineInstancer.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadow.cpp
-    ${PROJECT_SOURCE_DIR}/Source/Core/FontEffectShadowInstancer.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/FontEngineInterface.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/Geometry.cpp
     ${PROJECT_SOURCE_DIR}/Source/Core/GeometryUtilities.cpp

+ 4 - 4
Include/RmlUi/Core/ConvolutionFilter.h

@@ -44,8 +44,8 @@ class ConvolutionFilter
 public:
 	enum FilterOperation
 	{
-		// The result is the median value of all the filtered pixels.
-		MEDIAN,
+		// The result is the mean value of all the filtered pixels.
+		MEAN,
 		// The result is the smallest value of all filtered pixels.
 		DILATION,
 		// The result is the largest value of all the filtered pixels.
@@ -58,7 +58,7 @@ public:
 	/// Initialises the filter. A filter must be initialised and populated with values before use.
 	/// @param[in] kernel_size The size of the filter's kernel each side of the origin. So, for example, a filter initialised with a size of 1 will store 9 values.
 	/// @param[in] operation The operation the filter conducts to determine the result.
-	bool Initialise(int kernel_size, FilterOperation operation = MEDIAN);
+	bool Initialise(int kernel_size, FilterOperation operation = MEAN);
 
 	/// Returns a reference to one of the rows of the filter kernel.
 	/// @param[in] index The index of the desired row.
@@ -74,7 +74,7 @@ public:
 	/// @param[in] source The opacity information for the source buffer.
 	/// @param[in] source_dimensions The size of the source region (in pixels). The stride is assumed to be equivalent to the horizontal width.
 	/// @param[in] source_offset The offset of the source region from the destination region. This is usually the same as the kernel size.
-	void Run(byte* destination, const Vector2i& destination_dimensions, int destination_stride, const byte* source, const Vector2i& source_dimensions, const Vector2i& source_offset) const;
+	void Run(byte* destination, Vector2i destination_dimensions, int destination_stride, const byte* source, Vector2i source_dimensions, Vector2i source_offset) const;
 
 private:
 	int kernel_size;

+ 1 - 1
Include/RmlUi/Core/FontEffect.h

@@ -38,7 +38,7 @@ namespace Core {
 	@author Peter Curry
  */
 
-class FontEffect
+class RMLUICORE_API FontEffect
 {
 public:
 	// Behind or in front of main text

+ 6 - 6
Source/Core/ConvolutionFilter.cpp

@@ -37,7 +37,7 @@ ConvolutionFilter::ConvolutionFilter()
 	kernel_size = 0;
 	kernel = nullptr;
 
-	operation = MEDIAN;
+	operation = MEAN;
 }
 
 ConvolutionFilter::~ConvolutionFilter()
@@ -73,7 +73,7 @@ float* ConvolutionFilter::operator[](int index)
 }
 
 // Runs the convolution filter.
-void ConvolutionFilter::Run(byte* destination, const Vector2i& destination_dimensions, int destination_stride, const byte* source, const Vector2i& source_dimensions, const Vector2i& source_offset) const
+void ConvolutionFilter::Run(byte* destination, const Vector2i destination_dimensions, int destination_stride, const byte* source, const Vector2i source_dimensions, const Vector2i source_offset) const
 {
 	for (int y = 0; y < destination_dimensions.y; ++y)
 	{
@@ -103,16 +103,16 @@ void ConvolutionFilter::Run(byte* destination, const Vector2i& destination_dimen
 
 					switch (operation)
 					{
-						case MEDIAN:	opacity += pixel_opacity; break;
-						case DILATION:	opacity = Math::Max(opacity, pixel_opacity); break;
-						case EROSION:	opacity = num_pixels == 0 ? pixel_opacity : Math::Min(opacity, pixel_opacity); break;
+						case MEAN:      opacity += pixel_opacity; break;
+						case DILATION:  opacity = Math::Max(opacity, pixel_opacity); break;
+						case EROSION:   opacity = num_pixels == 0 ? pixel_opacity : Math::Min(opacity, pixel_opacity); break;
 					}
 
 					++num_pixels;
 				}
 			}
 
-			if (operation == MEDIAN)
+			if (operation == MEAN)
 				opacity /= num_pixels;
 
 			opacity = Math::Min(255, opacity);

+ 2 - 2
Source/Core/Factory.cpp

@@ -40,8 +40,8 @@
 #include "ElementImage.h"
 #include "ElementTextDefault.h"
 #include "EventInstancerDefault.h"
-#include "FontEffectOutlineInstancer.h"
-#include "FontEffectShadowInstancer.h"
+#include "FontEffectOutline.h"
+#include "FontEffectShadow.h"
 #include "PluginRegistry.h"
 #include "PropertyParserColour.h"
 #include "StreamFile.h"

+ 36 - 0
Source/Core/FontEffectOutline.cpp

@@ -102,5 +102,41 @@ void FontEffectOutline::GenerateGlyphTexture(byte* destination_data, const Vecto
 	filter.Run(destination_data, destination_dimensions, destination_stride, glyph.bitmap_data, glyph.bitmap_dimensions, Vector2i(width, width));
 }
 
+
+
+
+
+FontEffectOutlineInstancer::FontEffectOutlineInstancer() : id_width(PropertyId::Invalid), id_color(PropertyId::Invalid)
+{
+	id_width = RegisterProperty("width", "1px", true).AddParser("length").GetId();
+	id_color = RegisterProperty("color", "white", false).AddParser("color").GetId();
+	RegisterShorthand("font-effect", "width, color", ShorthandType::FallThrough);
+}
+
+FontEffectOutlineInstancer::~FontEffectOutlineInstancer()
+{
+}
+
+// Instances an outline font effect.
+SharedPtr<FontEffect> FontEffectOutlineInstancer::InstanceFontEffect(const String& RMLUI_UNUSED_PARAMETER(name), const PropertyDictionary& properties)
+{
+	RMLUI_UNUSED(name);
+
+	float width = properties.GetProperty(id_width)->Get< float >();
+	Colourb color = properties.GetProperty(id_color)->Get< Colourb >();
+
+	auto font_effect = std::make_shared<FontEffectOutline>();
+	if (font_effect->Initialise(Math::RealToInteger(width)))
+	{
+		font_effect->SetColour(color);
+		return font_effect;
+	}
+
+	return nullptr;
+}
+
+
+
+
 }
 }

+ 22 - 2
Source/Core/FontEffectOutline.h

@@ -31,12 +31,11 @@
 
 #include "../../Include/RmlUi/Core/ConvolutionFilter.h"
 #include "../../Include/RmlUi/Core/FontEffect.h"
+#include "../../Include/RmlUi/Core/FontEffectInstancer.h"
 
 namespace Rml {
 namespace Core {
 
-class ConvolutionFilter;
-
 /**
 	A concrete font effect for rendering outlines around text.
 
@@ -77,6 +76,27 @@ private:
 	ConvolutionFilter filter;
 };
 
+
+
+/**
+	A concrete font effect instancer for the outline effect.
+
+	@author Peter Curry
+ */
+
+class FontEffectOutlineInstancer : public FontEffectInstancer
+{
+public:
+	FontEffectOutlineInstancer();
+	virtual ~FontEffectOutlineInstancer();
+
+	SharedPtr<FontEffect> InstanceFontEffect(const String& name, const PropertyDictionary& properties) override;
+
+private:
+	PropertyId id_width, id_color;
+};
+
+
 }
 }
 

+ 0 - 66
Source/Core/FontEffectOutlineInstancer.cpp

@@ -1,66 +0,0 @@
-/*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#include "precompiled.h"
-#include "FontEffectOutlineInstancer.h"
-#include "FontEffectOutline.h"
-
-namespace Rml {
-namespace Core {
-
-FontEffectOutlineInstancer::FontEffectOutlineInstancer() : id_width(PropertyId::Invalid), id_color(PropertyId::Invalid)
-{
-	id_width = RegisterProperty("width", "1px", true).AddParser("length").GetId();
-	id_color = RegisterProperty("color", "white", false).AddParser("color").GetId();
-	RegisterShorthand("font-effect", "width, color", ShorthandType::FallThrough);
-}
-
-FontEffectOutlineInstancer::~FontEffectOutlineInstancer()
-{
-}
-
-// Instances an outline font effect.
-SharedPtr<FontEffect> FontEffectOutlineInstancer::InstanceFontEffect(const String& RMLUI_UNUSED_PARAMETER(name), const PropertyDictionary& properties)
-{
-	RMLUI_UNUSED(name);
-
-	float width = properties.GetProperty(id_width)->Get< float >();
-	Colourb color = properties.GetProperty(id_color)->Get< Colourb >();
-
-	auto font_effect = std::make_shared<FontEffectOutline>();
-	if (font_effect->Initialise(Math::RealToInteger(width)))
-	{
-		font_effect->SetColour(color);
-		return font_effect;
-	}
-
-	return nullptr;
-}
-
-}
-}

+ 0 - 58
Source/Core/FontEffectOutlineInstancer.h

@@ -1,58 +0,0 @@
-/*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#ifndef RMLUICOREFONTEFFECTOUTLINEINSTANCER_H
-#define RMLUICOREFONTEFFECTOUTLINEINSTANCER_H
-
-#include "../../Include/RmlUi/Core/FontEffectInstancer.h"
-
-namespace Rml {
-namespace Core {
-
-/**
-	A concrete font effect instancer for the outline effect.
-
-	@author Peter Curry
- */
-
-class FontEffectOutlineInstancer : public FontEffectInstancer
-{
-public:
-	FontEffectOutlineInstancer();
-	virtual ~FontEffectOutlineInstancer();
-
-	SharedPtr<FontEffect> InstanceFontEffect(const String& name, const PropertyDictionary& properties) override;
-
-private:
-	PropertyId id_width, id_color;
-};
-
-}
-}
-
-#endif

+ 36 - 0
Source/Core/FontEffectShadow.cpp

@@ -64,5 +64,41 @@ bool FontEffectShadow::GetGlyphMetrics(Vector2i& origin, Vector2i& RMLUI_UNUSED_
 	return true;
 }
 
+
+
+FontEffectShadowInstancer::FontEffectShadowInstancer() : id_offset_x(PropertyId::Invalid), id_offset_y(PropertyId::Invalid), id_color(PropertyId::Invalid)
+{
+	id_offset_x = RegisterProperty("offset-x", "0px", true).AddParser("length").GetId();
+	id_offset_y = RegisterProperty("offset-y", "0px", true).AddParser("length").GetId();
+	id_color = RegisterProperty("color", "white", false).AddParser("color").GetId();
+	RegisterShorthand("offset", "offset-x, offset-y", ShorthandType::FallThrough);
+	RegisterShorthand("font-effect", "offset-x, offset-y, color", ShorthandType::FallThrough);
+}
+
+FontEffectShadowInstancer::~FontEffectShadowInstancer()
+{
+}
+
+SharedPtr<FontEffect> FontEffectShadowInstancer::InstanceFontEffect(const String& RMLUI_UNUSED_PARAMETER(name), const PropertyDictionary& properties)
+{
+	RMLUI_UNUSED(name);
+
+	Vector2i offset;
+	offset.x = Math::RealToInteger(properties.GetProperty(id_offset_x)->Get< float >());
+	offset.y = Math::RealToInteger(properties.GetProperty(id_offset_y)->Get< float >());
+	Colourb color = properties.GetProperty(id_color)->Get< Colourb >();
+
+	auto font_effect = std::make_shared<FontEffectShadow>();
+	if (font_effect->Initialise(offset))
+	{
+		font_effect->SetColour(color);
+		return font_effect;
+	}
+
+	return nullptr;
+}
+
+
+
 }
 }

+ 22 - 0
Source/Core/FontEffectShadow.h

@@ -30,6 +30,7 @@
 #define RMLUICOREFONTEFFECTSHADOW_H
 
 #include "../../Include/RmlUi/Core/FontEffect.h"
+#include "../../Include/RmlUi/Core/FontEffectInstancer.h"
 
 namespace Rml {
 namespace Core {
@@ -66,6 +67,27 @@ private:
 	Vector2i offset;
 };
 
+
+
+/**
+	A concrete font effect instancer for the shadow effect.
+
+	@author Peter Curry
+ */
+
+class FontEffectShadowInstancer : public FontEffectInstancer
+{
+public:
+	FontEffectShadowInstancer();
+	virtual ~FontEffectShadowInstancer();
+
+	SharedPtr<FontEffect> InstanceFontEffect(const String& name, const PropertyDictionary& properties) override;
+
+private:
+	PropertyId id_offset_x, id_offset_y, id_color;
+};
+
+
 }
 }
 

+ 0 - 69
Source/Core/FontEffectShadowInstancer.cpp

@@ -1,69 +0,0 @@
-/*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#include "precompiled.h"
-#include "FontEffectShadowInstancer.h"
-#include "FontEffectShadow.h"
-
-namespace Rml {
-namespace Core {
-
-FontEffectShadowInstancer::FontEffectShadowInstancer() : id_offset_x(PropertyId::Invalid), id_offset_y(PropertyId::Invalid), id_color(PropertyId::Invalid)
-{
-	id_offset_x = RegisterProperty("offset-x", "0px", true).AddParser("length").GetId();
-	id_offset_y = RegisterProperty("offset-y", "0px", true).AddParser("length").GetId();
-	id_color = RegisterProperty("color", "white", false).AddParser("color").GetId();
-	RegisterShorthand("offset", "offset-x, offset-y", ShorthandType::FallThrough);
-	RegisterShorthand("font-effect", "offset-x, offset-y, color", ShorthandType::FallThrough);
-}
-
-FontEffectShadowInstancer::~FontEffectShadowInstancer()
-{
-}
-
-SharedPtr<FontEffect> FontEffectShadowInstancer::InstanceFontEffect(const String& RMLUI_UNUSED_PARAMETER(name), const PropertyDictionary& properties)
-{
-	RMLUI_UNUSED(name);
-
-	Vector2i offset;
-	offset.x = Math::RealToInteger(properties.GetProperty(id_offset_x)->Get< float >());
-	offset.y = Math::RealToInteger(properties.GetProperty(id_offset_y)->Get< float >());
-	Colourb color = properties.GetProperty(id_color)->Get< Colourb >();
-
-	auto font_effect = std::make_shared<FontEffectShadow>();
-	if (font_effect->Initialise(offset))
-	{
-		font_effect->SetColour(color);
-		return font_effect;
-	}
-
-	return nullptr;
-}
-
-}
-}

+ 0 - 58
Source/Core/FontEffectShadowInstancer.h

@@ -1,58 +0,0 @@
-/*
- * This source file is part of RmlUi, the HTML/CSS Interface Middleware
- *
- * For the latest information, see http://github.com/mikke89/RmlUi
- *
- * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
- * Copyright (c) 2019 The RmlUi Team, and contributors
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- * 
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#ifndef RMLUICOREFontEffectShadowInstancer_H
-#define RMLUICOREFontEffectShadowInstancer_H
-
-#include "../../Include/RmlUi/Core/FontEffectInstancer.h"
-
-namespace Rml {
-namespace Core {
-
-/**
-	A concrete font effect instancer for the shadow effect.
-
-	@author Peter Curry
- */
-
-class FontEffectShadowInstancer : public FontEffectInstancer
-{
-public:
-	FontEffectShadowInstancer();
-	virtual ~FontEffectShadowInstancer();
-
-	SharedPtr<FontEffect> InstanceFontEffect(const String& name, const PropertyDictionary& properties) override;
-
-private:
-	PropertyId id_offset_x, id_offset_y, id_color;
-};
-
-}
-}
-
-#endif