diff --git a/Msdfgen.vcxproj b/Msdfgen.vcxproj index a01daa1..81f4857 100644 --- a/Msdfgen.vcxproj +++ b/Msdfgen.vcxproj @@ -464,9 +464,11 @@ + + - + @@ -496,8 +498,9 @@ + - + diff --git a/Msdfgen.vcxproj.filters b/Msdfgen.vcxproj.filters index 95b8b6a..e4d9b4d 100644 --- a/Msdfgen.vcxproj.filters +++ b/Msdfgen.vcxproj.filters @@ -117,12 +117,18 @@ Core - - Core - Extensions + + Core + + + Core + + + Core + @@ -200,12 +206,15 @@ Core - - Core - Extensions + + Core + + + Core + diff --git a/core/Projection.cpp b/core/Projection.cpp new file mode 100644 index 0000000..fa2f5e2 --- /dev/null +++ b/core/Projection.cpp @@ -0,0 +1,42 @@ + +#include "Projection.h" + +namespace msdfgen { + +Projection::Projection() : scale(1), translate(0) { } + +Projection::Projection(const Vector2 &scale, const Vector2 &translate) : scale(scale), translate(translate) { } + +Point2 Projection::project(const Point2 &coord) const { + return scale*(coord+translate); +} + +Point2 Projection::unproject(const Point2 &coord) const { + return coord/scale-translate; +} + +Vector2 Projection::projectVector(const Vector2 &vector) const { + return scale*vector; +} + +Vector2 Projection::unprojectVector(const Vector2 &vector) const { + return vector/scale; +} + +double Projection::projectX(double x) const { + return scale.x*(x+translate.x); +} + +double Projection::projectY(double y) const { + return scale.y*(y+translate.y); +} + +double Projection::unprojectX(double x) const { + return x/scale.x-translate.x; +} + +double Projection::unprojectY(double y) const { + return y/scale.y-translate.y; +} + +} diff --git a/core/Projection.h b/core/Projection.h new file mode 100644 index 0000000..7cdb1c3 --- /dev/null +++ b/core/Projection.h @@ -0,0 +1,37 @@ + +#pragma once + +#include "Vector2.h" + +namespace msdfgen { + +/// A transformation from shape coordinates to pixel coordinates. +class Projection { + +public: + Projection(); + Projection(const Vector2 &scale, const Vector2 &translate); + /// Converts the shape coordinate to pixel coordinate. + Point2 project(const Point2 &coord) const; + /// Converts the pixel coordinate to shape coordinate. + Point2 unproject(const Point2 &coord) const; + /// Converts the vector to pixel coordinate space. + Vector2 projectVector(const Vector2 &vector) const; + /// Converts the vector from pixel coordinate space. + Vector2 unprojectVector(const Vector2 &vector) const; + /// Converts the X-coordinate from shape to pixel coordinate space. + double projectX(double x) const; + /// Converts the Y-coordinate from shape to pixel coordinate space. + double projectY(double y) const; + /// Converts the X-coordinate from pixel to shape coordinate space. + double unprojectX(double x) const; + /// Converts the Y-coordinate from pixel to shape coordinate space. + double unprojectY(double y) const; + +private: + Vector2 scale; + Vector2 translate; + +}; + +} diff --git a/core/generator-config.h b/core/generator-config.h new file mode 100644 index 0000000..8f07cca --- /dev/null +++ b/core/generator-config.h @@ -0,0 +1,31 @@ + +#pragma once + +#define MSDFGEN_DEFAULT_ARTIFACT_PATCHER_MIN_IMPROVE_RATIO 1.001 + +namespace msdfgen { + +/// The configuration of the distance field generator algorithm. +struct GeneratorConfig { + /// Specifies whether to use the version of the algorithm that supports overlapping contours with the same winding. May be set to false to improve performance when no such contours are present. + bool overlapSupport; + + inline explicit GeneratorConfig(bool overlapSupport = true) : overlapSupport(overlapSupport) { } +}; + +/// The configuration of the artifact patcher that processes the generated MSDF and fixes potential interpolation errors. +struct ArtifactPatcherConfig { + /// The mode of operation. + enum Mode { + DISABLED, + INDISCRIMINATE, + EDGE_PRIORITY, + EDGE_ONLY + } mode; + /// The minimum ratio of improvement required to patch a pixel. Must be greater than or equal to 1. + double minImproveRatio; + + inline explicit ArtifactPatcherConfig(Mode mode = EDGE_PRIORITY, double minImproveRatio = MSDFGEN_DEFAULT_ARTIFACT_PATCHER_MIN_IMPROVE_RATIO) : mode(mode), minImproveRatio(minImproveRatio) { } +}; + +} diff --git a/core/msdf-edge-artifact-patcher.cpp b/core/msdf-artifact-patcher.cpp similarity index 85% rename from core/msdf-edge-artifact-patcher.cpp rename to core/msdf-artifact-patcher.cpp index 2b5cdd0..6be6bc4 100644 --- a/core/msdf-edge-artifact-patcher.cpp +++ b/core/msdf-artifact-patcher.cpp @@ -1,5 +1,5 @@ -#include "msdf-edge-artifact-patcher.h" +#include "msdf-artifact-patcher.h" #include #include @@ -118,14 +118,14 @@ void findHotspots(std::vector &hotspots, const BitmapConstRef } template