add msdfgen for windows
This commit is contained in:
@@ -14,6 +14,7 @@ public class Render2D : EngineModule
|
||||
base.Setup(options);
|
||||
|
||||
options.PrivateDependencies.Add("freetype");
|
||||
options.PrivateDependencies.Add("msdfgen");
|
||||
|
||||
options.PrivateDefinitions.Add("RENDER2D_USE_LINE_AA");
|
||||
}
|
||||
|
||||
21
Source/ThirdParty/msdfgen/LICENSE.txt
vendored
Normal file
21
Source/ThirdParty/msdfgen/LICENSE.txt
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2014 - 2025 Viktor Chlumsky
|
||||
|
||||
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.
|
||||
45
Source/ThirdParty/msdfgen/msdfgen.Build.cs
vendored
Normal file
45
Source/ThirdParty/msdfgen/msdfgen.Build.cs
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.IO;
|
||||
using Flax.Build;
|
||||
using Flax.Build.NativeCpp;
|
||||
|
||||
/// <summary>
|
||||
/// https://github.com/Chlumsky/msdfgen
|
||||
/// </summary>
|
||||
public class msdfgen : DepsModule
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
|
||||
LicenseType = LicenseTypes.MIT;
|
||||
LicenseFilePath = "LICENSE.TXT";
|
||||
|
||||
// Merge third-party modules into engine binary
|
||||
BinaryModuleName = "FlaxEngine";
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Setup(BuildOptions options)
|
||||
{
|
||||
base.Setup(options);
|
||||
|
||||
var depsRoot = options.DepsFolder;
|
||||
switch (options.Platform.Target)
|
||||
{
|
||||
case TargetPlatform.Windows:
|
||||
options.OutputFiles.Add(Path.Combine(depsRoot, "msdfgen-core.lib"));
|
||||
break;
|
||||
case TargetPlatform.Linux:
|
||||
case TargetPlatform.Mac:
|
||||
// todo
|
||||
//options.OutputFiles.Add(Path.Combine(depsRoot, "msdfgen-core.a"));
|
||||
break;
|
||||
default: throw new InvalidPlatformException(options.Platform.Target);
|
||||
}
|
||||
|
||||
options.PublicIncludePaths.Add(Path.Combine(Globals.EngineRoot, @"Source\ThirdParty\msdfgen"));
|
||||
}
|
||||
}
|
||||
4
Source/ThirdParty/msdfgen/msdfgen.h
vendored
Normal file
4
Source/ThirdParty/msdfgen/msdfgen.h
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "msdfgen/msdfgen.h"
|
||||
50
Source/ThirdParty/msdfgen/msdfgen/core/Bitmap.h
vendored
Normal file
50
Source/ThirdParty/msdfgen/msdfgen/core/Bitmap.h
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// A 2D image bitmap with N channels of type T. Pixel memory is managed by the class.
|
||||
template <typename T, int N = 1>
|
||||
class Bitmap {
|
||||
|
||||
public:
|
||||
Bitmap();
|
||||
Bitmap(int width, int height);
|
||||
Bitmap(const BitmapConstRef<T, N> &orig);
|
||||
Bitmap(const Bitmap<T, N> &orig);
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
Bitmap(Bitmap<T, N> &&orig);
|
||||
#endif
|
||||
~Bitmap();
|
||||
Bitmap<T, N> &operator=(const BitmapConstRef<T, N> &orig);
|
||||
Bitmap<T, N> &operator=(const Bitmap<T, N> &orig);
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
Bitmap<T, N> &operator=(Bitmap<T, N> &&orig);
|
||||
#endif
|
||||
/// Bitmap width in pixels.
|
||||
int width() const;
|
||||
/// Bitmap height in pixels.
|
||||
int height() const;
|
||||
T *operator()(int x, int y);
|
||||
const T *operator()(int x, int y) const;
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
explicit operator T *();
|
||||
explicit operator const T *() const;
|
||||
#else
|
||||
operator T *();
|
||||
operator const T *() const;
|
||||
#endif
|
||||
operator BitmapRef<T, N>();
|
||||
operator BitmapConstRef<T, N>() const;
|
||||
|
||||
private:
|
||||
T *pixels;
|
||||
int w, h;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#include "Bitmap.hpp"
|
||||
117
Source/ThirdParty/msdfgen/msdfgen/core/Bitmap.hpp
vendored
Normal file
117
Source/ThirdParty/msdfgen/msdfgen/core/Bitmap.hpp
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
|
||||
#include "Bitmap.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N>::Bitmap() : pixels(NULL), w(0), h(0) { }
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N>::Bitmap(int width, int height) : w(width), h(height) {
|
||||
pixels = new T[N*w*h];
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N>::Bitmap(const BitmapConstRef<T, N> &orig) : w(orig.width), h(orig.height) {
|
||||
pixels = new T[N*w*h];
|
||||
memcpy(pixels, orig.pixels, sizeof(T)*N*w*h);
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N>::Bitmap(const Bitmap<T, N> &orig) : w(orig.w), h(orig.h) {
|
||||
pixels = new T[N*w*h];
|
||||
memcpy(pixels, orig.pixels, sizeof(T)*N*w*h);
|
||||
}
|
||||
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N>::Bitmap(Bitmap<T, N> &&orig) : pixels(orig.pixels), w(orig.w), h(orig.h) {
|
||||
orig.pixels = NULL;
|
||||
orig.w = 0, orig.h = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N>::~Bitmap() {
|
||||
delete [] pixels;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N> &Bitmap<T, N>::operator=(const BitmapConstRef<T, N> &orig) {
|
||||
if (pixels != orig.pixels) {
|
||||
delete [] pixels;
|
||||
w = orig.width, h = orig.height;
|
||||
pixels = new T[N*w*h];
|
||||
memcpy(pixels, orig.pixels, sizeof(T)*N*w*h);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N> &Bitmap<T, N>::operator=(const Bitmap<T, N> &orig) {
|
||||
if (this != &orig) {
|
||||
delete [] pixels;
|
||||
w = orig.w, h = orig.h;
|
||||
pixels = new T[N*w*h];
|
||||
memcpy(pixels, orig.pixels, sizeof(T)*N*w*h);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N> &Bitmap<T, N>::operator=(Bitmap<T, N> &&orig) {
|
||||
if (this != &orig) {
|
||||
delete [] pixels;
|
||||
pixels = orig.pixels;
|
||||
w = orig.w, h = orig.h;
|
||||
orig.pixels = NULL;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T, int N>
|
||||
int Bitmap<T, N>::width() const {
|
||||
return w;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
int Bitmap<T, N>::height() const {
|
||||
return h;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
T *Bitmap<T, N>::operator()(int x, int y) {
|
||||
return pixels+N*(w*y+x);
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
const T *Bitmap<T, N>::operator()(int x, int y) const {
|
||||
return pixels+N*(w*y+x);
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N>::operator T *() {
|
||||
return pixels;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N>::operator const T *() const {
|
||||
return pixels;
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N>::operator BitmapRef<T, N>() {
|
||||
return BitmapRef<T, N>(pixels, w, h);
|
||||
}
|
||||
|
||||
template <typename T, int N>
|
||||
Bitmap<T, N>::operator BitmapConstRef<T, N>() const {
|
||||
return BitmapConstRef<T, N>(pixels, w, h);
|
||||
}
|
||||
|
||||
}
|
||||
41
Source/ThirdParty/msdfgen/msdfgen/core/BitmapRef.hpp
vendored
Normal file
41
Source/ThirdParty/msdfgen/msdfgen/core/BitmapRef.hpp
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object.
|
||||
template <typename T, int N = 1>
|
||||
struct BitmapRef {
|
||||
|
||||
T *pixels;
|
||||
int width, height;
|
||||
|
||||
inline BitmapRef() : pixels(NULL), width(0), height(0) { }
|
||||
inline BitmapRef(T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { }
|
||||
|
||||
inline T *operator()(int x, int y) const {
|
||||
return pixels+N*(width*y+x);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/// Constant reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object.
|
||||
template <typename T, int N = 1>
|
||||
struct BitmapConstRef {
|
||||
|
||||
const T *pixels;
|
||||
int width, height;
|
||||
|
||||
inline BitmapConstRef() : pixels(NULL), width(0), height(0) { }
|
||||
inline BitmapConstRef(const T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { }
|
||||
inline BitmapConstRef(const BitmapRef<T, N> &orig) : pixels(orig.pixels), width(orig.width), height(orig.height) { }
|
||||
|
||||
inline const T *operator()(int x, int y) const {
|
||||
return pixels+N*(width*y+x);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
34
Source/ThirdParty/msdfgen/msdfgen/core/Contour.h
vendored
Normal file
34
Source/ThirdParty/msdfgen/msdfgen/core/Contour.h
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "EdgeHolder.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// A single closed contour of a shape.
|
||||
class Contour {
|
||||
|
||||
public:
|
||||
/// The sequence of edges that make up the contour.
|
||||
std::vector<EdgeHolder> edges;
|
||||
|
||||
/// Adds an edge to the contour.
|
||||
void addEdge(const EdgeHolder &edge);
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
void addEdge(EdgeHolder &&edge);
|
||||
#endif
|
||||
/// Creates a new edge in the contour and returns its reference.
|
||||
EdgeHolder &addEdge();
|
||||
/// Adjusts the bounding box to fit the contour.
|
||||
void bound(double &l, double &b, double &r, double &t) const;
|
||||
/// Adjusts the bounding box to fit the contour border's mitered corners.
|
||||
void boundMiters(double &l, double &b, double &r, double &t, double border, double miterLimit, int polarity) const;
|
||||
/// Computes the winding of the contour. Returns 1 if positive, -1 if negative.
|
||||
int winding() const;
|
||||
/// Reverses the sequence of edges on the contour.
|
||||
void reverse();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
36
Source/ThirdParty/msdfgen/msdfgen/core/DistanceMapping.h
vendored
Normal file
36
Source/ThirdParty/msdfgen/msdfgen/core/DistanceMapping.h
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Range.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Linear transformation of signed distance values.
|
||||
class DistanceMapping {
|
||||
|
||||
public:
|
||||
/// Explicitly designates value as distance delta rather than an absolute distance.
|
||||
class Delta {
|
||||
public:
|
||||
double value;
|
||||
inline explicit Delta(double distanceDelta) : value(distanceDelta) { }
|
||||
inline operator double() const { return value; }
|
||||
};
|
||||
|
||||
static DistanceMapping inverse(Range range);
|
||||
|
||||
DistanceMapping();
|
||||
DistanceMapping(Range range);
|
||||
double operator()(double d) const;
|
||||
double operator()(Delta d) const;
|
||||
DistanceMapping inverse() const;
|
||||
|
||||
private:
|
||||
double scale;
|
||||
double translate;
|
||||
|
||||
inline DistanceMapping(double scale, double translate) : scale(scale), translate(translate) { }
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
20
Source/ThirdParty/msdfgen/msdfgen/core/EdgeColor.h
vendored
Normal file
20
Source/ThirdParty/msdfgen/msdfgen/core/EdgeColor.h
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Edge color specifies which color channels an edge belongs to.
|
||||
enum EdgeColor {
|
||||
BLACK = 0,
|
||||
RED = 1,
|
||||
GREEN = 2,
|
||||
YELLOW = 3,
|
||||
BLUE = 4,
|
||||
MAGENTA = 5,
|
||||
CYAN = 6,
|
||||
WHITE = 7
|
||||
};
|
||||
|
||||
}
|
||||
41
Source/ThirdParty/msdfgen/msdfgen/core/EdgeHolder.h
vendored
Normal file
41
Source/ThirdParty/msdfgen/msdfgen/core/EdgeHolder.h
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "edge-segments.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Container for a single edge of dynamic type.
|
||||
class EdgeHolder {
|
||||
|
||||
public:
|
||||
/// Swaps the edges held by a and b.
|
||||
static void swap(EdgeHolder &a, EdgeHolder &b);
|
||||
|
||||
inline EdgeHolder() : edgeSegment() { }
|
||||
inline EdgeHolder(EdgeSegment *segment) : edgeSegment(segment) { }
|
||||
inline EdgeHolder(Point2 p0, Point2 p1, EdgeColor edgeColor = WHITE) : edgeSegment(EdgeSegment::create(p0, p1, edgeColor)) { }
|
||||
inline EdgeHolder(Point2 p0, Point2 p1, Point2 p2, EdgeColor edgeColor = WHITE) : edgeSegment(EdgeSegment::create(p0, p1, p2, edgeColor)) { }
|
||||
inline EdgeHolder(Point2 p0, Point2 p1, Point2 p2, Point2 p3, EdgeColor edgeColor = WHITE) : edgeSegment(EdgeSegment::create(p0, p1, p2, p3, edgeColor)) { }
|
||||
EdgeHolder(const EdgeHolder &orig);
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
EdgeHolder(EdgeHolder &&orig);
|
||||
#endif
|
||||
~EdgeHolder();
|
||||
EdgeHolder &operator=(const EdgeHolder &orig);
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
EdgeHolder &operator=(EdgeHolder &&orig);
|
||||
#endif
|
||||
EdgeSegment &operator*();
|
||||
const EdgeSegment &operator*() const;
|
||||
EdgeSegment *operator->();
|
||||
const EdgeSegment *operator->() const;
|
||||
operator EdgeSegment *();
|
||||
operator const EdgeSegment *() const;
|
||||
|
||||
private:
|
||||
EdgeSegment *edgeSegment;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
55
Source/ThirdParty/msdfgen/msdfgen/core/MSDFErrorCorrection.h
vendored
Normal file
55
Source/ThirdParty/msdfgen/msdfgen/core/MSDFErrorCorrection.h
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SDFTransformation.h"
|
||||
#include "Shape.h"
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Performs error correction on a computed MSDF to eliminate interpolation artifacts. This is a low-level class, you may want to use the API in msdf-error-correction.h instead.
|
||||
class MSDFErrorCorrection {
|
||||
|
||||
public:
|
||||
/// Stencil flags.
|
||||
enum Flags {
|
||||
/// Texel marked as potentially causing interpolation errors.
|
||||
ERROR = 1,
|
||||
/// Texel marked as protected. Protected texels are only given the error flag if they cause inversion artifacts.
|
||||
PROTECTED = 2
|
||||
};
|
||||
|
||||
MSDFErrorCorrection();
|
||||
explicit MSDFErrorCorrection(const BitmapRef<byte, 1> &stencil, const SDFTransformation &transformation);
|
||||
/// Sets the minimum ratio between the actual and maximum expected distance delta to be considered an error.
|
||||
void setMinDeviationRatio(double minDeviationRatio);
|
||||
/// Sets the minimum ratio between the pre-correction distance error and the post-correction distance error.
|
||||
void setMinImproveRatio(double minImproveRatio);
|
||||
/// Flags all texels that are interpolated at corners as protected.
|
||||
void protectCorners(const Shape &shape);
|
||||
/// Flags all texels that contribute to edges as protected.
|
||||
template <int N>
|
||||
void protectEdges(const BitmapConstRef<float, N> &sdf);
|
||||
/// Flags all texels as protected.
|
||||
void protectAll();
|
||||
/// Flags texels that are expected to cause interpolation artifacts based on analysis of the SDF only.
|
||||
template <int N>
|
||||
void findErrors(const BitmapConstRef<float, N> &sdf);
|
||||
/// Flags texels that are expected to cause interpolation artifacts based on analysis of the SDF and comparison with the exact shape distance.
|
||||
template <template <typename> class ContourCombiner, int N>
|
||||
void findErrors(const BitmapConstRef<float, N> &sdf, const Shape &shape);
|
||||
/// Modifies the MSDF so that all texels with the error flag are converted to single-channel.
|
||||
template <int N>
|
||||
void apply(const BitmapRef<float, N> &sdf) const;
|
||||
/// Returns the stencil in its current state (see Flags).
|
||||
BitmapConstRef<byte, 1> getStencil() const;
|
||||
|
||||
private:
|
||||
BitmapRef<byte, 1> stencil;
|
||||
SDFTransformation transformation;
|
||||
double minDeviationRatio;
|
||||
double minImproveRatio;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
37
Source/ThirdParty/msdfgen/msdfgen/core/Projection.h
vendored
Normal file
37
Source/ThirdParty/msdfgen/msdfgen/core/Projection.h
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Vector2.hpp"
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
46
Source/ThirdParty/msdfgen/msdfgen/core/Range.hpp
vendored
Normal file
46
Source/ThirdParty/msdfgen/msdfgen/core/Range.hpp
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/**
|
||||
* Represents the range between two real values.
|
||||
* For example, the range of representable signed distances.
|
||||
*/
|
||||
struct Range {
|
||||
|
||||
double lower, upper;
|
||||
|
||||
inline Range(double symmetricalWidth = 0) : lower(-.5*symmetricalWidth), upper(.5*symmetricalWidth) { }
|
||||
|
||||
inline Range(double lowerBound, double upperBound) : lower(lowerBound), upper(upperBound) { }
|
||||
|
||||
inline Range &operator*=(double factor) {
|
||||
lower *= factor;
|
||||
upper *= factor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Range &operator/=(double divisor) {
|
||||
lower /= divisor;
|
||||
upper /= divisor;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Range operator*(double factor) const {
|
||||
return Range(lower*factor, upper*factor);
|
||||
}
|
||||
|
||||
inline Range operator/(double divisor) const {
|
||||
return Range(lower/divisor, upper/divisor);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
inline Range operator*(double factor, const Range &range) {
|
||||
return Range(factor*range.lower, factor*range.upper);
|
||||
}
|
||||
|
||||
}
|
||||
24
Source/ThirdParty/msdfgen/msdfgen/core/SDFTransformation.h
vendored
Normal file
24
Source/ThirdParty/msdfgen/msdfgen/core/SDFTransformation.h
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Projection.h"
|
||||
#include "DistanceMapping.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/**
|
||||
* Full signed distance field transformation specifies both spatial transformation (Projection)
|
||||
* as well as distance value transformation (DistanceMapping).
|
||||
*/
|
||||
class SDFTransformation : public Projection {
|
||||
|
||||
public:
|
||||
DistanceMapping distanceMapping;
|
||||
|
||||
inline SDFTransformation() { }
|
||||
|
||||
inline SDFTransformation(const Projection &projection, const DistanceMapping &distanceMapping) : Projection(projection), distanceMapping(distanceMapping) { }
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
56
Source/ThirdParty/msdfgen/msdfgen/core/Scanline.h
vendored
Normal file
56
Source/ThirdParty/msdfgen/msdfgen/core/Scanline.h
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "base.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Fill rule dictates how intersection total is interpreted during rasterization.
|
||||
enum FillRule {
|
||||
FILL_NONZERO,
|
||||
FILL_ODD, // "even-odd"
|
||||
FILL_POSITIVE,
|
||||
FILL_NEGATIVE
|
||||
};
|
||||
|
||||
/// Resolves the number of intersection into a binary fill value based on fill rule.
|
||||
bool interpretFillRule(int intersections, FillRule fillRule);
|
||||
|
||||
/// Represents a horizontal scanline intersecting a shape.
|
||||
class Scanline {
|
||||
|
||||
public:
|
||||
/// An intersection with the scanline.
|
||||
struct Intersection {
|
||||
/// X coordinate.
|
||||
double x;
|
||||
/// Normalized Y direction of the oriented edge at the point of intersection.
|
||||
int direction;
|
||||
};
|
||||
|
||||
static double overlap(const Scanline &a, const Scanline &b, double xFrom, double xTo, FillRule fillRule);
|
||||
|
||||
Scanline();
|
||||
/// Populates the intersection list.
|
||||
void setIntersections(const std::vector<Intersection> &intersections);
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
void setIntersections(std::vector<Intersection> &&intersections);
|
||||
#endif
|
||||
/// Returns the number of intersections left of x.
|
||||
int countIntersections(double x) const;
|
||||
/// Returns the total sign of intersections left of x.
|
||||
int sumIntersections(double x) const;
|
||||
/// Decides whether the scanline is filled at x based on fill rule.
|
||||
bool filled(double x, FillRule fillRule) const;
|
||||
|
||||
private:
|
||||
std::vector<Intersection> intersections;
|
||||
mutable int lastIndex;
|
||||
|
||||
void preprocess();
|
||||
int moveTo(double x) const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
53
Source/ThirdParty/msdfgen/msdfgen/core/Shape.h
vendored
Normal file
53
Source/ThirdParty/msdfgen/msdfgen/core/Shape.h
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "Contour.h"
|
||||
#include "Scanline.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
// Threshold of the dot product of adjacent edge directions to be considered convergent.
|
||||
#define MSDFGEN_CORNER_DOT_EPSILON .000001
|
||||
|
||||
/// Vector shape representation.
|
||||
class Shape {
|
||||
|
||||
public:
|
||||
struct Bounds {
|
||||
double l, b, r, t;
|
||||
};
|
||||
|
||||
/// The list of contours the shape consists of.
|
||||
std::vector<Contour> contours;
|
||||
/// Specifies whether the shape uses bottom-to-top (false) or top-to-bottom (true) Y coordinates.
|
||||
bool inverseYAxis;
|
||||
|
||||
Shape();
|
||||
/// Adds a contour.
|
||||
void addContour(const Contour &contour);
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
void addContour(Contour &&contour);
|
||||
#endif
|
||||
/// Adds a blank contour and returns its reference.
|
||||
Contour &addContour();
|
||||
/// Normalizes the shape geometry for distance field generation.
|
||||
void normalize();
|
||||
/// Performs basic checks to determine if the object represents a valid shape.
|
||||
bool validate() const;
|
||||
/// Adjusts the bounding box to fit the shape.
|
||||
void bound(double &l, double &b, double &r, double &t) const;
|
||||
/// Adjusts the bounding box to fit the shape border's mitered corners.
|
||||
void boundMiters(double &l, double &b, double &r, double &t, double border, double miterLimit, int polarity) const;
|
||||
/// Computes the minimum bounding box that fits the shape, optionally with a (mitered) border.
|
||||
Bounds getBounds(double border = 0, double miterLimit = 0, int polarity = 0) const;
|
||||
/// Outputs the scanline that intersects the shape at y.
|
||||
void scanline(Scanline &line, double y) const;
|
||||
/// Returns the total number of edge segments
|
||||
int edgeCount() const;
|
||||
/// Assumes its contours are unoriented (even-odd fill rule). Attempts to orient them to conform to the non-zero winding rule.
|
||||
void orientContours();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
37
Source/ThirdParty/msdfgen/msdfgen/core/ShapeDistanceFinder.h
vendored
Normal file
37
Source/ThirdParty/msdfgen/msdfgen/core/ShapeDistanceFinder.h
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "Vector2.hpp"
|
||||
#include "edge-selectors.h"
|
||||
#include "contour-combiners.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Finds the distance between a point and a Shape. ContourCombiner dictates the distance metric and its data type.
|
||||
template <class ContourCombiner>
|
||||
class ShapeDistanceFinder {
|
||||
|
||||
public:
|
||||
typedef typename ContourCombiner::DistanceType DistanceType;
|
||||
|
||||
// Passed shape object must persist until the distance finder is destroyed!
|
||||
explicit ShapeDistanceFinder(const Shape &shape);
|
||||
/// Finds the distance from origin. Not thread-safe! Is fastest when subsequent queries are close together.
|
||||
DistanceType distance(const Point2 &origin);
|
||||
|
||||
/// Finds the distance between shape and origin. Does not allocate result cache used to optimize performance of multiple queries.
|
||||
static DistanceType oneShotDistance(const Shape &shape, const Point2 &origin);
|
||||
|
||||
private:
|
||||
const Shape &shape;
|
||||
ContourCombiner contourCombiner;
|
||||
std::vector<typename ContourCombiner::EdgeSelectorType::EdgeCache> shapeEdgeCache;
|
||||
|
||||
};
|
||||
|
||||
typedef ShapeDistanceFinder<SimpleContourCombiner<TrueDistanceSelector> > SimpleTrueShapeDistanceFinder;
|
||||
|
||||
}
|
||||
|
||||
#include "ShapeDistanceFinder.hpp"
|
||||
60
Source/ThirdParty/msdfgen/msdfgen/core/ShapeDistanceFinder.hpp
vendored
Normal file
60
Source/ThirdParty/msdfgen/msdfgen/core/ShapeDistanceFinder.hpp
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
#include "ShapeDistanceFinder.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
template <class ContourCombiner>
|
||||
ShapeDistanceFinder<ContourCombiner>::ShapeDistanceFinder(const Shape &shape) : shape(shape), contourCombiner(shape), shapeEdgeCache(shape.edgeCount()) { }
|
||||
|
||||
template <class ContourCombiner>
|
||||
typename ShapeDistanceFinder<ContourCombiner>::DistanceType ShapeDistanceFinder<ContourCombiner>::distance(const Point2 &origin) {
|
||||
contourCombiner.reset(origin);
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
typename ContourCombiner::EdgeSelectorType::EdgeCache *edgeCache = shapeEdgeCache.data();
|
||||
#else
|
||||
typename ContourCombiner::EdgeSelectorType::EdgeCache *edgeCache = shapeEdgeCache.empty() ? NULL : &shapeEdgeCache[0];
|
||||
#endif
|
||||
|
||||
for (std::vector<Contour>::const_iterator contour = shape.contours.begin(); contour != shape.contours.end(); ++contour) {
|
||||
if (!contour->edges.empty()) {
|
||||
typename ContourCombiner::EdgeSelectorType &edgeSelector = contourCombiner.edgeSelector(int(contour-shape.contours.begin()));
|
||||
|
||||
const EdgeSegment *prevEdge = contour->edges.size() >= 2 ? *(contour->edges.end()-2) : *contour->edges.begin();
|
||||
const EdgeSegment *curEdge = contour->edges.back();
|
||||
for (std::vector<EdgeHolder>::const_iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge) {
|
||||
const EdgeSegment *nextEdge = *edge;
|
||||
edgeSelector.addEdge(*edgeCache++, prevEdge, curEdge, nextEdge);
|
||||
prevEdge = curEdge;
|
||||
curEdge = nextEdge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return contourCombiner.distance();
|
||||
}
|
||||
|
||||
template <class ContourCombiner>
|
||||
typename ShapeDistanceFinder<ContourCombiner>::DistanceType ShapeDistanceFinder<ContourCombiner>::oneShotDistance(const Shape &shape, const Point2 &origin) {
|
||||
ContourCombiner contourCombiner(shape);
|
||||
contourCombiner.reset(origin);
|
||||
|
||||
for (std::vector<Contour>::const_iterator contour = shape.contours.begin(); contour != shape.contours.end(); ++contour) {
|
||||
if (!contour->edges.empty()) {
|
||||
typename ContourCombiner::EdgeSelectorType &edgeSelector = contourCombiner.edgeSelector(int(contour-shape.contours.begin()));
|
||||
|
||||
const EdgeSegment *prevEdge = contour->edges.size() >= 2 ? *(contour->edges.end()-2) : *contour->edges.begin();
|
||||
const EdgeSegment *curEdge = contour->edges.back();
|
||||
for (std::vector<EdgeHolder>::const_iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge) {
|
||||
const EdgeSegment *nextEdge = *edge;
|
||||
typename ContourCombiner::EdgeSelectorType::EdgeCache dummy;
|
||||
edgeSelector.addEdge(dummy, prevEdge, curEdge, nextEdge);
|
||||
prevEdge = curEdge;
|
||||
curEdge = nextEdge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return contourCombiner.distance();
|
||||
}
|
||||
|
||||
}
|
||||
38
Source/ThirdParty/msdfgen/msdfgen/core/SignedDistance.hpp
vendored
Normal file
38
Source/ThirdParty/msdfgen/msdfgen/core/SignedDistance.hpp
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include <cfloat>
|
||||
#include "base.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Represents a signed distance and alignment, which together can be compared to uniquely determine the closest edge segment.
|
||||
class SignedDistance {
|
||||
|
||||
public:
|
||||
double distance;
|
||||
double dot;
|
||||
|
||||
inline SignedDistance() : distance(-DBL_MAX), dot(0) { }
|
||||
inline SignedDistance(double dist, double d) : distance(dist), dot(d) { }
|
||||
|
||||
};
|
||||
|
||||
inline bool operator<(const SignedDistance a, const SignedDistance b) {
|
||||
return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot < b.dot);
|
||||
}
|
||||
|
||||
inline bool operator>(const SignedDistance a, const SignedDistance b) {
|
||||
return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot > b.dot);
|
||||
}
|
||||
|
||||
inline bool operator<=(const SignedDistance a, const SignedDistance b) {
|
||||
return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot <= b.dot);
|
||||
}
|
||||
|
||||
inline bool operator>=(const SignedDistance a, const SignedDistance b) {
|
||||
return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot >= b.dot);
|
||||
}
|
||||
|
||||
}
|
||||
167
Source/ThirdParty/msdfgen/msdfgen/core/Vector2.hpp
vendored
Normal file
167
Source/ThirdParty/msdfgen/msdfgen/core/Vector2.hpp
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include "base.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/**
|
||||
* A 2-dimensional euclidean floating-point vector.
|
||||
* @author Viktor Chlumsky
|
||||
*/
|
||||
struct Vector2 {
|
||||
|
||||
double x, y;
|
||||
|
||||
inline Vector2(double val = 0) : x(val), y(val) { }
|
||||
|
||||
inline Vector2(double x, double y) : x(x), y(y) { }
|
||||
|
||||
/// Sets the vector to zero.
|
||||
inline void reset() {
|
||||
x = 0, y = 0;
|
||||
}
|
||||
|
||||
/// Sets individual elements of the vector.
|
||||
inline void set(double newX, double newY) {
|
||||
x = newX, y = newY;
|
||||
}
|
||||
|
||||
/// Returns the vector's squared length.
|
||||
inline double squaredLength() const {
|
||||
return x*x+y*y;
|
||||
}
|
||||
|
||||
/// Returns the vector's length.
|
||||
inline double length() const {
|
||||
return sqrt(x*x+y*y);
|
||||
}
|
||||
|
||||
/// Returns the normalized vector - one that has the same direction but unit length.
|
||||
inline Vector2 normalize(bool allowZero = false) const {
|
||||
if (double len = length())
|
||||
return Vector2(x/len, y/len);
|
||||
return Vector2(0, !allowZero);
|
||||
}
|
||||
|
||||
/// Returns a vector with the same length that is orthogonal to this one.
|
||||
inline Vector2 getOrthogonal(bool polarity = true) const {
|
||||
return polarity ? Vector2(-y, x) : Vector2(y, -x);
|
||||
}
|
||||
|
||||
/// Returns a vector with unit length that is orthogonal to this one.
|
||||
inline Vector2 getOrthonormal(bool polarity = true, bool allowZero = false) const {
|
||||
if (double len = length())
|
||||
return polarity ? Vector2(-y/len, x/len) : Vector2(y/len, -x/len);
|
||||
return polarity ? Vector2(0, !allowZero) : Vector2(0, -!allowZero);
|
||||
}
|
||||
|
||||
#ifdef MSDFGEN_USE_CPP11
|
||||
inline explicit operator bool() const {
|
||||
return x || y;
|
||||
}
|
||||
#else
|
||||
inline operator const void *() const {
|
||||
return x || y ? this : NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline Vector2 &operator+=(const Vector2 other) {
|
||||
x += other.x, y += other.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector2 &operator-=(const Vector2 other) {
|
||||
x -= other.x, y -= other.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector2 &operator*=(const Vector2 other) {
|
||||
x *= other.x, y *= other.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector2 &operator/=(const Vector2 other) {
|
||||
x /= other.x, y /= other.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector2 &operator*=(double value) {
|
||||
x *= value, y *= value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector2 &operator/=(double value) {
|
||||
x /= value, y /= value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/// A vector may also represent a point, which shall be differentiated semantically using the alias Point2.
|
||||
typedef Vector2 Point2;
|
||||
|
||||
/// Dot product of two vectors.
|
||||
inline double dotProduct(const Vector2 a, const Vector2 b) {
|
||||
return a.x*b.x+a.y*b.y;
|
||||
}
|
||||
|
||||
/// A special version of the cross product for 2D vectors (returns scalar value).
|
||||
inline double crossProduct(const Vector2 a, const Vector2 b) {
|
||||
return a.x*b.y-a.y*b.x;
|
||||
}
|
||||
|
||||
inline bool operator==(const Vector2 a, const Vector2 b) {
|
||||
return a.x == b.x && a.y == b.y;
|
||||
}
|
||||
|
||||
inline bool operator!=(const Vector2 a, const Vector2 b) {
|
||||
return a.x != b.x || a.y != b.y;
|
||||
}
|
||||
|
||||
inline Vector2 operator+(const Vector2 v) {
|
||||
return v;
|
||||
}
|
||||
|
||||
inline Vector2 operator-(const Vector2 v) {
|
||||
return Vector2(-v.x, -v.y);
|
||||
}
|
||||
|
||||
inline bool operator!(const Vector2 v) {
|
||||
return !v.x && !v.y;
|
||||
}
|
||||
|
||||
inline Vector2 operator+(const Vector2 a, const Vector2 b) {
|
||||
return Vector2(a.x+b.x, a.y+b.y);
|
||||
}
|
||||
|
||||
inline Vector2 operator-(const Vector2 a, const Vector2 b) {
|
||||
return Vector2(a.x-b.x, a.y-b.y);
|
||||
}
|
||||
|
||||
inline Vector2 operator*(const Vector2 a, const Vector2 b) {
|
||||
return Vector2(a.x*b.x, a.y*b.y);
|
||||
}
|
||||
|
||||
inline Vector2 operator/(const Vector2 a, const Vector2 b) {
|
||||
return Vector2(a.x/b.x, a.y/b.y);
|
||||
}
|
||||
|
||||
inline Vector2 operator*(double a, const Vector2 b) {
|
||||
return Vector2(a*b.x, a*b.y);
|
||||
}
|
||||
|
||||
inline Vector2 operator/(double a, const Vector2 b) {
|
||||
return Vector2(a/b.x, a/b.y);
|
||||
}
|
||||
|
||||
inline Vector2 operator*(const Vector2 a, double b) {
|
||||
return Vector2(a.x*b, a.y*b);
|
||||
}
|
||||
|
||||
inline Vector2 operator/(const Vector2 a, double b) {
|
||||
return Vector2(a.x/b, a.y/b);
|
||||
}
|
||||
|
||||
}
|
||||
63
Source/ThirdParty/msdfgen/msdfgen/core/arithmetics.hpp
vendored
Normal file
63
Source/ThirdParty/msdfgen/msdfgen/core/arithmetics.hpp
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cmath>
|
||||
#include "base.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Returns the smaller of the arguments.
|
||||
template <typename T>
|
||||
inline T min(T a, T b) {
|
||||
return b < a ? b : a;
|
||||
}
|
||||
|
||||
/// Returns the larger of the arguments.
|
||||
template <typename T>
|
||||
inline T max(T a, T b) {
|
||||
return a < b ? b : a;
|
||||
}
|
||||
|
||||
/// Returns the middle out of three values
|
||||
template <typename T>
|
||||
inline T median(T a, T b, T c) {
|
||||
return max(min(a, b), min(max(a, b), c));
|
||||
}
|
||||
|
||||
/// Returns the weighted average of a and b.
|
||||
template <typename T, typename S>
|
||||
inline T mix(T a, T b, S weight) {
|
||||
return T((S(1)-weight)*a+weight*b);
|
||||
}
|
||||
|
||||
/// Clamps the number to the interval from 0 to 1.
|
||||
template <typename T>
|
||||
inline T clamp(T n) {
|
||||
return n >= T(0) && n <= T(1) ? n : T(n > T(0));
|
||||
}
|
||||
|
||||
/// Clamps the number to the interval from 0 to b.
|
||||
template <typename T>
|
||||
inline T clamp(T n, T b) {
|
||||
return n >= T(0) && n <= b ? n : T(n > T(0))*b;
|
||||
}
|
||||
|
||||
/// Clamps the number to the interval from a to b.
|
||||
template <typename T>
|
||||
inline T clamp(T n, T a, T b) {
|
||||
return n >= a && n <= b ? n : n < a ? a : b;
|
||||
}
|
||||
|
||||
/// Returns 1 for positive values, -1 for negative values, and 0 for zero.
|
||||
template <typename T>
|
||||
inline int sign(T n) {
|
||||
return (T(0) < n)-(n < T(0));
|
||||
}
|
||||
|
||||
/// Returns 1 for non-negative values and -1 for negative values.
|
||||
template <typename T>
|
||||
inline int nonZeroSign(T n) {
|
||||
return 2*(n > T(0))-1;
|
||||
}
|
||||
|
||||
}
|
||||
16
Source/ThirdParty/msdfgen/msdfgen/core/base.h
vendored
Normal file
16
Source/ThirdParty/msdfgen/msdfgen/core/base.h
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
// This file needs to be included first for all MSDFgen sources
|
||||
|
||||
#ifndef MSDFGEN_PUBLIC
|
||||
#include <msdfgen/msdfgen-config.h>
|
||||
#endif
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
typedef unsigned char byte;
|
||||
|
||||
}
|
||||
25
Source/ThirdParty/msdfgen/msdfgen/core/bitmap-interpolation.hpp
vendored
Normal file
25
Source/ThirdParty/msdfgen/msdfgen/core/bitmap-interpolation.hpp
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arithmetics.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
template <typename T, int N>
|
||||
static void interpolate(T *output, const BitmapConstRef<T, N> &bitmap, Point2 pos) {
|
||||
pos -= .5;
|
||||
int l = (int) floor(pos.x);
|
||||
int b = (int) floor(pos.y);
|
||||
int r = l+1;
|
||||
int t = b+1;
|
||||
double lr = pos.x-l;
|
||||
double bt = pos.y-b;
|
||||
l = clamp(l, bitmap.width-1), r = clamp(r, bitmap.width-1);
|
||||
b = clamp(b, bitmap.height-1), t = clamp(t, bitmap.height-1);
|
||||
for (int i = 0; i < N; ++i)
|
||||
output[i] = mix(mix(bitmap(l, b)[i], bitmap(r, b)[i], lr), mix(bitmap(l, t)[i], bitmap(r, t)[i], lr), bt);
|
||||
}
|
||||
|
||||
}
|
||||
47
Source/ThirdParty/msdfgen/msdfgen/core/contour-combiners.h
vendored
Normal file
47
Source/ThirdParty/msdfgen/msdfgen/core/contour-combiners.h
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Shape.h"
|
||||
#include "edge-selectors.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Simply selects the nearest contour.
|
||||
template <class EdgeSelector>
|
||||
class SimpleContourCombiner {
|
||||
|
||||
public:
|
||||
typedef EdgeSelector EdgeSelectorType;
|
||||
typedef typename EdgeSelector::DistanceType DistanceType;
|
||||
|
||||
explicit SimpleContourCombiner(const Shape &shape);
|
||||
void reset(const Point2 &p);
|
||||
EdgeSelector &edgeSelector(int i);
|
||||
DistanceType distance() const;
|
||||
|
||||
private:
|
||||
EdgeSelector shapeEdgeSelector;
|
||||
|
||||
};
|
||||
|
||||
/// Selects the nearest contour that actually forms a border between filled and unfilled area.
|
||||
template <class EdgeSelector>
|
||||
class OverlappingContourCombiner {
|
||||
|
||||
public:
|
||||
typedef EdgeSelector EdgeSelectorType;
|
||||
typedef typename EdgeSelector::DistanceType DistanceType;
|
||||
|
||||
explicit OverlappingContourCombiner(const Shape &shape);
|
||||
void reset(const Point2 &p);
|
||||
EdgeSelector &edgeSelector(int i);
|
||||
DistanceType distance() const;
|
||||
|
||||
private:
|
||||
Point2 p;
|
||||
std::vector<int> windings;
|
||||
std::vector<EdgeSelector> edgeSelectors;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
11
Source/ThirdParty/msdfgen/msdfgen/core/convergent-curve-ordering.h
vendored
Normal file
11
Source/ThirdParty/msdfgen/msdfgen/core/convergent-curve-ordering.h
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "edge-segments.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// For curves a, b converging at P = a->point(1) = b->point(0) with the same (opposite) direction, determines the relative ordering in which they exit P (i.e. whether a is to the left or right of b at the smallest positive radius around P)
|
||||
int convergentCurveOrdering(const EdgeSegment *a, const EdgeSegment *b);
|
||||
|
||||
}
|
||||
29
Source/ThirdParty/msdfgen/msdfgen/core/edge-coloring.h
vendored
Normal file
29
Source/ThirdParty/msdfgen/msdfgen/core/edge-coloring.h
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
#define MSDFGEN_EDGE_LENGTH_PRECISION 4
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/** Assigns colors to edges of the shape in accordance to the multi-channel distance field technique.
|
||||
* May split some edges if necessary.
|
||||
* angleThreshold specifies the maximum angle (in radians) to be considered a corner, for example 3 (~172 degrees).
|
||||
* Values below 1/2 PI will be treated as the external angle.
|
||||
*/
|
||||
void edgeColoringSimple(Shape &shape, double angleThreshold, unsigned long long seed = 0);
|
||||
|
||||
/** The alternative "ink trap" coloring strategy is designed for better results with typefaces
|
||||
* that use ink traps as a design feature. It guarantees that even if all edges that are shorter than
|
||||
* both their neighboring edges are removed, the coloring remains consistent with the established rules.
|
||||
*/
|
||||
void edgeColoringInkTrap(Shape &shape, double angleThreshold, unsigned long long seed = 0);
|
||||
|
||||
/** The alternative coloring by distance tries to use different colors for edges that are close together.
|
||||
* This should theoretically be the best strategy on average. However, since it needs to compute the distance
|
||||
* between all pairs of edges, and perform a graph optimization task, it is much slower than the rest.
|
||||
*/
|
||||
void edgeColoringByDistance(Shape &shape, double angleThreshold, unsigned long long seed = 0);
|
||||
|
||||
}
|
||||
146
Source/ThirdParty/msdfgen/msdfgen/core/edge-segments.h
vendored
Normal file
146
Source/ThirdParty/msdfgen/msdfgen/core/edge-segments.h
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Vector2.hpp"
|
||||
#include "SignedDistance.hpp"
|
||||
#include "EdgeColor.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
// Parameters for iterative search of closest point on a cubic Bezier curve. Increase for higher precision.
|
||||
#define MSDFGEN_CUBIC_SEARCH_STARTS 4
|
||||
#define MSDFGEN_CUBIC_SEARCH_STEPS 4
|
||||
|
||||
/// An abstract edge segment.
|
||||
class EdgeSegment {
|
||||
|
||||
public:
|
||||
EdgeColor color;
|
||||
|
||||
static EdgeSegment *create(Point2 p0, Point2 p1, EdgeColor edgeColor = WHITE);
|
||||
static EdgeSegment *create(Point2 p0, Point2 p1, Point2 p2, EdgeColor edgeColor = WHITE);
|
||||
static EdgeSegment *create(Point2 p0, Point2 p1, Point2 p2, Point2 p3, EdgeColor edgeColor = WHITE);
|
||||
|
||||
EdgeSegment(EdgeColor edgeColor = WHITE) : color(edgeColor) { }
|
||||
virtual ~EdgeSegment() { }
|
||||
/// Creates a copy of the edge segment.
|
||||
virtual EdgeSegment *clone() const = 0;
|
||||
/// Returns the numeric code of the edge segment's type.
|
||||
virtual int type() const = 0;
|
||||
/// Returns the array of control points.
|
||||
virtual const Point2 *controlPoints() const = 0;
|
||||
/// Returns the point on the edge specified by the parameter (between 0 and 1).
|
||||
virtual Point2 point(double param) const = 0;
|
||||
/// Returns the direction the edge has at the point specified by the parameter.
|
||||
virtual Vector2 direction(double param) const = 0;
|
||||
/// Returns the change of direction (second derivative) at the point specified by the parameter.
|
||||
virtual Vector2 directionChange(double param) const = 0;
|
||||
/// Returns the minimum signed distance between origin and the edge.
|
||||
virtual SignedDistance signedDistance(Point2 origin, double ¶m) const = 0;
|
||||
/// Converts a previously retrieved signed distance from origin to perpendicular distance.
|
||||
virtual void distanceToPerpendicularDistance(SignedDistance &distance, Point2 origin, double param) const;
|
||||
/// Outputs a list of (at most three) intersections (their X coordinates) with an infinite horizontal scanline at y and returns how many there are.
|
||||
virtual int scanlineIntersections(double x[3], int dy[3], double y) const = 0;
|
||||
/// Adjusts the bounding box to fit the edge segment.
|
||||
virtual void bound(double &l, double &b, double &r, double &t) const = 0;
|
||||
|
||||
/// Reverses the edge (swaps its start point and end point).
|
||||
virtual void reverse() = 0;
|
||||
/// Moves the start point of the edge segment.
|
||||
virtual void moveStartPoint(Point2 to) = 0;
|
||||
/// Moves the end point of the edge segment.
|
||||
virtual void moveEndPoint(Point2 to) = 0;
|
||||
/// Splits the edge segments into thirds which together represent the original edge.
|
||||
virtual void splitInThirds(EdgeSegment *&part0, EdgeSegment *&part1, EdgeSegment *&part2) const = 0;
|
||||
|
||||
};
|
||||
|
||||
/// A line segment.
|
||||
class LinearSegment : public EdgeSegment {
|
||||
|
||||
public:
|
||||
enum EdgeType {
|
||||
EDGE_TYPE = 1
|
||||
};
|
||||
|
||||
Point2 p[2];
|
||||
|
||||
LinearSegment(Point2 p0, Point2 p1, EdgeColor edgeColor = WHITE);
|
||||
LinearSegment *clone() const;
|
||||
int type() const;
|
||||
const Point2 *controlPoints() const;
|
||||
Point2 point(double param) const;
|
||||
Vector2 direction(double param) const;
|
||||
Vector2 directionChange(double param) const;
|
||||
double length() const;
|
||||
SignedDistance signedDistance(Point2 origin, double ¶m) const;
|
||||
int scanlineIntersections(double x[3], int dy[3], double y) const;
|
||||
void bound(double &l, double &b, double &r, double &t) const;
|
||||
|
||||
void reverse();
|
||||
void moveStartPoint(Point2 to);
|
||||
void moveEndPoint(Point2 to);
|
||||
void splitInThirds(EdgeSegment *&part0, EdgeSegment *&part1, EdgeSegment *&part2) const;
|
||||
|
||||
};
|
||||
|
||||
/// A quadratic Bezier curve.
|
||||
class QuadraticSegment : public EdgeSegment {
|
||||
|
||||
public:
|
||||
enum EdgeType {
|
||||
EDGE_TYPE = 2
|
||||
};
|
||||
|
||||
Point2 p[3];
|
||||
|
||||
QuadraticSegment(Point2 p0, Point2 p1, Point2 p2, EdgeColor edgeColor = WHITE);
|
||||
QuadraticSegment *clone() const;
|
||||
int type() const;
|
||||
const Point2 *controlPoints() const;
|
||||
Point2 point(double param) const;
|
||||
Vector2 direction(double param) const;
|
||||
Vector2 directionChange(double param) const;
|
||||
double length() const;
|
||||
SignedDistance signedDistance(Point2 origin, double ¶m) const;
|
||||
int scanlineIntersections(double x[3], int dy[3], double y) const;
|
||||
void bound(double &l, double &b, double &r, double &t) const;
|
||||
|
||||
void reverse();
|
||||
void moveStartPoint(Point2 to);
|
||||
void moveEndPoint(Point2 to);
|
||||
void splitInThirds(EdgeSegment *&part0, EdgeSegment *&part1, EdgeSegment *&part2) const;
|
||||
|
||||
EdgeSegment *convertToCubic() const;
|
||||
|
||||
};
|
||||
|
||||
/// A cubic Bezier curve.
|
||||
class CubicSegment : public EdgeSegment {
|
||||
|
||||
public:
|
||||
enum EdgeType {
|
||||
EDGE_TYPE = 3
|
||||
};
|
||||
|
||||
Point2 p[4];
|
||||
|
||||
CubicSegment(Point2 p0, Point2 p1, Point2 p2, Point2 p3, EdgeColor edgeColor = WHITE);
|
||||
CubicSegment *clone() const;
|
||||
int type() const;
|
||||
const Point2 *controlPoints() const;
|
||||
Point2 point(double param) const;
|
||||
Vector2 direction(double param) const;
|
||||
Vector2 directionChange(double param) const;
|
||||
SignedDistance signedDistance(Point2 origin, double ¶m) const;
|
||||
int scanlineIntersections(double x[3], int dy[3], double y) const;
|
||||
void bound(double &l, double &b, double &r, double &t) const;
|
||||
|
||||
void reverse();
|
||||
void moveStartPoint(Point2 to);
|
||||
void moveEndPoint(Point2 to);
|
||||
void splitInThirds(EdgeSegment *&part0, EdgeSegment *&part1, EdgeSegment *&part2) const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
117
Source/ThirdParty/msdfgen/msdfgen/core/edge-selectors.h
vendored
Normal file
117
Source/ThirdParty/msdfgen/msdfgen/core/edge-selectors.h
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Vector2.hpp"
|
||||
#include "SignedDistance.hpp"
|
||||
#include "edge-segments.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
struct MultiDistance {
|
||||
double r, g, b;
|
||||
};
|
||||
struct MultiAndTrueDistance : MultiDistance {
|
||||
double a;
|
||||
};
|
||||
|
||||
/// Selects the nearest edge by its true distance.
|
||||
class TrueDistanceSelector {
|
||||
|
||||
public:
|
||||
typedef double DistanceType;
|
||||
|
||||
struct EdgeCache {
|
||||
Point2 point;
|
||||
double absDistance;
|
||||
|
||||
EdgeCache();
|
||||
};
|
||||
|
||||
void reset(const Point2 &p);
|
||||
void addEdge(EdgeCache &cache, const EdgeSegment *prevEdge, const EdgeSegment *edge, const EdgeSegment *nextEdge);
|
||||
void merge(const TrueDistanceSelector &other);
|
||||
DistanceType distance() const;
|
||||
|
||||
private:
|
||||
Point2 p;
|
||||
SignedDistance minDistance;
|
||||
|
||||
};
|
||||
|
||||
class PerpendicularDistanceSelectorBase {
|
||||
|
||||
public:
|
||||
struct EdgeCache {
|
||||
Point2 point;
|
||||
double absDistance;
|
||||
double aDomainDistance, bDomainDistance;
|
||||
double aPerpendicularDistance, bPerpendicularDistance;
|
||||
|
||||
EdgeCache();
|
||||
};
|
||||
|
||||
static bool getPerpendicularDistance(double &distance, const Vector2 &ep, const Vector2 &edgeDir);
|
||||
|
||||
PerpendicularDistanceSelectorBase();
|
||||
void reset(double delta);
|
||||
bool isEdgeRelevant(const EdgeCache &cache, const EdgeSegment *edge, const Point2 &p) const;
|
||||
void addEdgeTrueDistance(const EdgeSegment *edge, const SignedDistance &distance, double param);
|
||||
void addEdgePerpendicularDistance(double distance);
|
||||
void merge(const PerpendicularDistanceSelectorBase &other);
|
||||
double computeDistance(const Point2 &p) const;
|
||||
SignedDistance trueDistance() const;
|
||||
|
||||
private:
|
||||
SignedDistance minTrueDistance;
|
||||
double minNegativePerpendicularDistance;
|
||||
double minPositivePerpendicularDistance;
|
||||
const EdgeSegment *nearEdge;
|
||||
double nearEdgeParam;
|
||||
|
||||
};
|
||||
|
||||
/// Selects the nearest edge by its perpendicular distance.
|
||||
class PerpendicularDistanceSelector : public PerpendicularDistanceSelectorBase {
|
||||
|
||||
public:
|
||||
typedef double DistanceType;
|
||||
|
||||
void reset(const Point2 &p);
|
||||
void addEdge(EdgeCache &cache, const EdgeSegment *prevEdge, const EdgeSegment *edge, const EdgeSegment *nextEdge);
|
||||
DistanceType distance() const;
|
||||
|
||||
private:
|
||||
Point2 p;
|
||||
|
||||
};
|
||||
|
||||
/// Selects the nearest edge for each of the three channels by its perpendicular distance.
|
||||
class MultiDistanceSelector {
|
||||
|
||||
public:
|
||||
typedef MultiDistance DistanceType;
|
||||
typedef PerpendicularDistanceSelectorBase::EdgeCache EdgeCache;
|
||||
|
||||
void reset(const Point2 &p);
|
||||
void addEdge(EdgeCache &cache, const EdgeSegment *prevEdge, const EdgeSegment *edge, const EdgeSegment *nextEdge);
|
||||
void merge(const MultiDistanceSelector &other);
|
||||
DistanceType distance() const;
|
||||
SignedDistance trueDistance() const;
|
||||
|
||||
private:
|
||||
Point2 p;
|
||||
PerpendicularDistanceSelectorBase r, g, b;
|
||||
|
||||
};
|
||||
|
||||
/// Selects the nearest edge for each of the three color channels by its perpendicular distance and by true distance for the alpha channel.
|
||||
class MultiAndTrueDistanceSelector : public MultiDistanceSelector {
|
||||
|
||||
public:
|
||||
typedef MultiAndTrueDistance DistanceType;
|
||||
|
||||
DistanceType distance() const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
14
Source/ThirdParty/msdfgen/msdfgen/core/equation-solver.h
vendored
Normal file
14
Source/ThirdParty/msdfgen/msdfgen/core/equation-solver.h
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "base.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
// ax^2 + bx + c = 0
|
||||
int solveQuadratic(double x[2], double a, double b, double c);
|
||||
|
||||
// ax^3 + bx^2 + cx + d = 0
|
||||
int solveCubic(double x[3], double a, double b, double c, double d);
|
||||
|
||||
}
|
||||
11
Source/ThirdParty/msdfgen/msdfgen/core/export-svg.h
vendored
Normal file
11
Source/ThirdParty/msdfgen/msdfgen/core/export-svg.h
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Shape.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
bool saveSvgShape(const Shape &shape, const char *filename);
|
||||
bool saveSvgShape(const Shape &shape, const Shape::Bounds &bounds, const char *filename);
|
||||
|
||||
}
|
||||
66
Source/ThirdParty/msdfgen/msdfgen/core/generator-config.h
vendored
Normal file
66
Source/ThirdParty/msdfgen/msdfgen/core/generator-config.h
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
#ifndef MSDFGEN_PUBLIC
|
||||
#define MSDFGEN_PUBLIC // for DLL import/export
|
||||
#endif
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// The configuration of the MSDF error correction pass.
|
||||
struct ErrorCorrectionConfig {
|
||||
/// The default value of minDeviationRatio.
|
||||
static MSDFGEN_PUBLIC const double defaultMinDeviationRatio;
|
||||
/// The default value of minImproveRatio.
|
||||
static MSDFGEN_PUBLIC const double defaultMinImproveRatio;
|
||||
|
||||
/// Mode of operation.
|
||||
enum Mode {
|
||||
/// Skips error correction pass.
|
||||
DISABLED,
|
||||
/// Corrects all discontinuities of the distance field regardless if edges are adversely affected.
|
||||
INDISCRIMINATE,
|
||||
/// Corrects artifacts at edges and other discontinuous distances only if it does not affect edges or corners.
|
||||
EDGE_PRIORITY,
|
||||
/// Only corrects artifacts at edges.
|
||||
EDGE_ONLY
|
||||
} mode;
|
||||
/// Configuration of whether to use an algorithm that computes the exact shape distance at the positions of suspected artifacts. This algorithm can be much slower.
|
||||
enum DistanceCheckMode {
|
||||
/// Never computes exact shape distance.
|
||||
DO_NOT_CHECK_DISTANCE,
|
||||
/// Only computes exact shape distance at edges. Provides a good balance between speed and precision.
|
||||
CHECK_DISTANCE_AT_EDGE,
|
||||
/// Computes and compares the exact shape distance for each suspected artifact.
|
||||
ALWAYS_CHECK_DISTANCE
|
||||
} distanceCheckMode;
|
||||
/// The minimum ratio between the actual and maximum expected distance delta to be considered an error.
|
||||
double minDeviationRatio;
|
||||
/// The minimum ratio between the pre-correction distance error and the post-correction distance error. Has no effect for DO_NOT_CHECK_DISTANCE.
|
||||
double minImproveRatio;
|
||||
/// An optional buffer to avoid dynamic allocation. Must have at least as many bytes as the MSDF has pixels.
|
||||
byte *buffer;
|
||||
|
||||
inline explicit ErrorCorrectionConfig(Mode mode = EDGE_PRIORITY, DistanceCheckMode distanceCheckMode = CHECK_DISTANCE_AT_EDGE, double minDeviationRatio = defaultMinDeviationRatio, double minImproveRatio = defaultMinImproveRatio, byte *buffer = NULL) : mode(mode), distanceCheckMode(distanceCheckMode), minDeviationRatio(minDeviationRatio), minImproveRatio(minImproveRatio), buffer(buffer) { }
|
||||
};
|
||||
|
||||
/// 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 multi-channel distance field generator algorithm.
|
||||
struct MSDFGeneratorConfig : GeneratorConfig {
|
||||
/// Configuration of the error correction pass.
|
||||
ErrorCorrectionConfig errorCorrection;
|
||||
|
||||
inline MSDFGeneratorConfig() { }
|
||||
inline explicit MSDFGeneratorConfig(bool overlapSupport, const ErrorCorrectionConfig &errorCorrection = ErrorCorrectionConfig()) : GeneratorConfig(overlapSupport), errorCorrection(errorCorrection) { }
|
||||
};
|
||||
|
||||
}
|
||||
40
Source/ThirdParty/msdfgen/msdfgen/core/msdf-error-correction.h
vendored
Normal file
40
Source/ThirdParty/msdfgen/msdfgen/core/msdf-error-correction.h
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Vector2.hpp"
|
||||
#include "Range.hpp"
|
||||
#include "Projection.h"
|
||||
#include "SDFTransformation.h"
|
||||
#include "Shape.h"
|
||||
#include "BitmapRef.hpp"
|
||||
#include "generator-config.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Predicts potential artifacts caused by the interpolation of the MSDF and corrects them by converting nearby texels to single-channel.
|
||||
void msdfErrorCorrection(const BitmapRef<float, 3> &sdf, const Shape &shape, const SDFTransformation &transformation, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
|
||||
void msdfErrorCorrection(const BitmapRef<float, 4> &sdf, const Shape &shape, const SDFTransformation &transformation, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
|
||||
void msdfErrorCorrection(const BitmapRef<float, 3> &sdf, const Shape &shape, const Projection &projection, Range range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
|
||||
void msdfErrorCorrection(const BitmapRef<float, 4> &sdf, const Shape &shape, const Projection &projection, Range range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
|
||||
|
||||
/// Applies the simplified error correction to all discontiunous distances (INDISCRIMINATE mode). Does not need shape or translation.
|
||||
void msdfFastDistanceErrorCorrection(const BitmapRef<float, 3> &sdf, const SDFTransformation &transformation, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
void msdfFastDistanceErrorCorrection(const BitmapRef<float, 4> &sdf, const SDFTransformation &transformation, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
void msdfFastDistanceErrorCorrection(const BitmapRef<float, 3> &sdf, const Projection &projection, Range range, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
void msdfFastDistanceErrorCorrection(const BitmapRef<float, 4> &sdf, const Projection &projection, Range range, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
void msdfFastDistanceErrorCorrection(const BitmapRef<float, 3> &sdf, Range pxRange, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
void msdfFastDistanceErrorCorrection(const BitmapRef<float, 4> &sdf, Range pxRange, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
|
||||
/// Applies the simplified error correction to edges only (EDGE_ONLY mode). Does not need shape or translation.
|
||||
void msdfFastEdgeErrorCorrection(const BitmapRef<float, 3> &sdf, const SDFTransformation &transformation, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
void msdfFastEdgeErrorCorrection(const BitmapRef<float, 4> &sdf, const SDFTransformation &transformation, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
void msdfFastEdgeErrorCorrection(const BitmapRef<float, 3> &sdf, const Projection &projection, Range range, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
void msdfFastEdgeErrorCorrection(const BitmapRef<float, 4> &sdf, const Projection &projection, Range range, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
void msdfFastEdgeErrorCorrection(const BitmapRef<float, 3> &sdf, Range pxRange, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
void msdfFastEdgeErrorCorrection(const BitmapRef<float, 4> &sdf, Range pxRange, double minDeviationRatio = ErrorCorrectionConfig::defaultMinDeviationRatio);
|
||||
|
||||
/// The original version of the error correction algorithm.
|
||||
void msdfErrorCorrection_legacy(const BitmapRef<float, 3> &output, const Vector2 &threshold);
|
||||
void msdfErrorCorrection_legacy(const BitmapRef<float, 4> &output, const Vector2 &threshold);
|
||||
|
||||
}
|
||||
16
Source/ThirdParty/msdfgen/msdfgen/core/pixel-conversion.hpp
vendored
Normal file
16
Source/ThirdParty/msdfgen/msdfgen/core/pixel-conversion.hpp
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arithmetics.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
inline byte pixelFloatToByte(float x) {
|
||||
return byte(~int(255.5f-255.f*clamp(x)));
|
||||
}
|
||||
|
||||
inline float pixelByteToFloat(byte x) {
|
||||
return 1.f/255.f*float(x);
|
||||
}
|
||||
|
||||
}
|
||||
25
Source/ThirdParty/msdfgen/msdfgen/core/rasterization.h
vendored
Normal file
25
Source/ThirdParty/msdfgen/msdfgen/core/rasterization.h
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Vector2.hpp"
|
||||
#include "Shape.h"
|
||||
#include "Projection.h"
|
||||
#include "Scanline.h"
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Rasterizes the shape into a monochrome bitmap.
|
||||
void rasterize(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, FillRule fillRule = FILL_NONZERO);
|
||||
/// Fixes the sign of the input signed distance field, so that it matches the shape's rasterized fill.
|
||||
void distanceSignCorrection(const BitmapRef<float, 1> &sdf, const Shape &shape, const Projection &projection, FillRule fillRule = FILL_NONZERO);
|
||||
void distanceSignCorrection(const BitmapRef<float, 3> &sdf, const Shape &shape, const Projection &projection, FillRule fillRule = FILL_NONZERO);
|
||||
void distanceSignCorrection(const BitmapRef<float, 4> &sdf, const Shape &shape, const Projection &projection, FillRule fillRule = FILL_NONZERO);
|
||||
|
||||
// Old version of the function API's kept for backwards compatibility
|
||||
void rasterize(const BitmapRef<float, 1> &output, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule = FILL_NONZERO);
|
||||
void distanceSignCorrection(const BitmapRef<float, 1> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule = FILL_NONZERO);
|
||||
void distanceSignCorrection(const BitmapRef<float, 3> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule = FILL_NONZERO);
|
||||
void distanceSignCorrection(const BitmapRef<float, 4> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, FillRule fillRule = FILL_NONZERO);
|
||||
|
||||
}
|
||||
23
Source/ThirdParty/msdfgen/msdfgen/core/render-sdf.h
vendored
Normal file
23
Source/ThirdParty/msdfgen/msdfgen/core/render-sdf.h
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Vector2.hpp"
|
||||
#include "Range.hpp"
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Reconstructs the shape's appearance into output from the distance field sdf.
|
||||
void renderSDF(const BitmapRef<float, 1> &output, const BitmapConstRef<float, 1> &sdf, Range sdfPxRange = 0, float sdThreshold = .5f);
|
||||
void renderSDF(const BitmapRef<float, 3> &output, const BitmapConstRef<float, 1> &sdf, Range sdfPxRange = 0, float sdThreshold = .5f);
|
||||
void renderSDF(const BitmapRef<float, 1> &output, const BitmapConstRef<float, 3> &sdf, Range sdfPxRange = 0, float sdThreshold = .5f);
|
||||
void renderSDF(const BitmapRef<float, 3> &output, const BitmapConstRef<float, 3> &sdf, Range sdfPxRange = 0, float sdThreshold = .5f);
|
||||
void renderSDF(const BitmapRef<float, 1> &output, const BitmapConstRef<float, 4> &sdf, Range sdfPxRange = 0, float sdThreshold = .5f);
|
||||
void renderSDF(const BitmapRef<float, 4> &output, const BitmapConstRef<float, 4> &sdf, Range sdfPxRange = 0, float sdThreshold = .5f);
|
||||
|
||||
/// Snaps the values of the floating-point bitmaps into one of the 256 values representable in a standard 8-bit bitmap.
|
||||
void simulate8bit(const BitmapRef<float, 1> &bitmap);
|
||||
void simulate8bit(const BitmapRef<float, 3> &bitmap);
|
||||
void simulate8bit(const BitmapRef<float, 4> &bitmap);
|
||||
|
||||
}
|
||||
16
Source/ThirdParty/msdfgen/msdfgen/core/save-bmp.h
vendored
Normal file
16
Source/ThirdParty/msdfgen/msdfgen/core/save-bmp.h
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Saves the bitmap as a BMP file.
|
||||
bool saveBmp(const BitmapConstRef<byte, 1> &bitmap, const char *filename);
|
||||
bool saveBmp(const BitmapConstRef<byte, 3> &bitmap, const char *filename);
|
||||
bool saveBmp(const BitmapConstRef<byte, 4> &bitmap, const char *filename);
|
||||
bool saveBmp(const BitmapConstRef<float, 1> &bitmap, const char *filename);
|
||||
bool saveBmp(const BitmapConstRef<float, 3> &bitmap, const char *filename);
|
||||
bool saveBmp(const BitmapConstRef<float, 4> &bitmap, const char *filename);
|
||||
|
||||
}
|
||||
12
Source/ThirdParty/msdfgen/msdfgen/core/save-fl32.h
vendored
Normal file
12
Source/ThirdParty/msdfgen/msdfgen/core/save-fl32.h
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Saves the bitmap as an uncompressed floating-point FL32 file, which can be decoded trivially.
|
||||
template <int N>
|
||||
bool saveFl32(const BitmapConstRef<float, N> &bitmap, const char *filename);
|
||||
|
||||
}
|
||||
16
Source/ThirdParty/msdfgen/msdfgen/core/save-rgba.h
vendored
Normal file
16
Source/ThirdParty/msdfgen/msdfgen/core/save-rgba.h
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Saves the bitmap as a simple RGBA file, which can be decoded trivially.
|
||||
bool saveRgba(const BitmapConstRef<byte, 1> &bitmap, const char *filename);
|
||||
bool saveRgba(const BitmapConstRef<byte, 3> &bitmap, const char *filename);
|
||||
bool saveRgba(const BitmapConstRef<byte, 4> &bitmap, const char *filename);
|
||||
bool saveRgba(const BitmapConstRef<float, 1> &bitmap, const char *filename);
|
||||
bool saveRgba(const BitmapConstRef<float, 3> &bitmap, const char *filename);
|
||||
bool saveRgba(const BitmapConstRef<float, 4> &bitmap, const char *filename);
|
||||
|
||||
}
|
||||
13
Source/ThirdParty/msdfgen/msdfgen/core/save-tiff.h
vendored
Normal file
13
Source/ThirdParty/msdfgen/msdfgen/core/save-tiff.h
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Saves the bitmap as an uncompressed floating-point TIFF file.
|
||||
bool saveTiff(const BitmapConstRef<float, 1> &bitmap, const char *filename);
|
||||
bool saveTiff(const BitmapConstRef<float, 3> &bitmap, const char *filename);
|
||||
bool saveTiff(const BitmapConstRef<float, 4> &bitmap, const char *filename);
|
||||
|
||||
}
|
||||
30
Source/ThirdParty/msdfgen/msdfgen/core/sdf-error-estimation.h
vendored
Normal file
30
Source/ThirdParty/msdfgen/msdfgen/core/sdf-error-estimation.h
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Vector2.hpp"
|
||||
#include "Shape.h"
|
||||
#include "Projection.h"
|
||||
#include "Scanline.h"
|
||||
#include "BitmapRef.hpp"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Analytically constructs a scanline at y evaluating fill by linear interpolation of the SDF.
|
||||
void scanlineSDF(Scanline &line, const BitmapConstRef<float, 1> &sdf, const Projection &projection, double y, bool inverseYAxis = false);
|
||||
void scanlineSDF(Scanline &line, const BitmapConstRef<float, 3> &sdf, const Projection &projection, double y, bool inverseYAxis = false);
|
||||
void scanlineSDF(Scanline &line, const BitmapConstRef<float, 4> &sdf, const Projection &projection, double y, bool inverseYAxis = false);
|
||||
|
||||
/// Estimates the portion of the area that will be filled incorrectly when rendering using the SDF.
|
||||
double estimateSDFError(const BitmapConstRef<float, 1> &sdf, const Shape &shape, const Projection &projection, int scanlinesPerRow, FillRule fillRule = FILL_NONZERO);
|
||||
double estimateSDFError(const BitmapConstRef<float, 3> &sdf, const Shape &shape, const Projection &projection, int scanlinesPerRow, FillRule fillRule = FILL_NONZERO);
|
||||
double estimateSDFError(const BitmapConstRef<float, 4> &sdf, const Shape &shape, const Projection &projection, int scanlinesPerRow, FillRule fillRule = FILL_NONZERO);
|
||||
|
||||
// Old version of the function API's kept for backwards compatibility
|
||||
void scanlineSDF(Scanline &line, const BitmapConstRef<float, 1> &sdf, const Vector2 &scale, const Vector2 &translate, bool inverseYAxis, double y);
|
||||
void scanlineSDF(Scanline &line, const BitmapConstRef<float, 3> &sdf, const Vector2 &scale, const Vector2 &translate, bool inverseYAxis, double y);
|
||||
void scanlineSDF(Scanline &line, const BitmapConstRef<float, 4> &sdf, const Vector2 &scale, const Vector2 &translate, bool inverseYAxis, double y);
|
||||
double estimateSDFError(const BitmapConstRef<float, 1> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, int scanlinesPerRow, FillRule fillRule = FILL_NONZERO);
|
||||
double estimateSDFError(const BitmapConstRef<float, 3> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, int scanlinesPerRow, FillRule fillRule = FILL_NONZERO);
|
||||
double estimateSDFError(const BitmapConstRef<float, 4> &sdf, const Shape &shape, const Vector2 &scale, const Vector2 &translate, int scanlinesPerRow, FillRule fillRule = FILL_NONZERO);
|
||||
|
||||
}
|
||||
15
Source/ThirdParty/msdfgen/msdfgen/core/shape-description.h
vendored
Normal file
15
Source/ThirdParty/msdfgen/msdfgen/core/shape-description.h
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include "Shape.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Deserializes a text description of a vector shape into output.
|
||||
bool readShapeDescription(FILE *input, Shape &output, bool *colorsSpecified = NULL);
|
||||
bool readShapeDescription(const char *input, Shape &output, bool *colorsSpecified = NULL);
|
||||
/// Serializes a shape object into a text description.
|
||||
bool writeShapeDescription(FILE *output, const Shape &shape);
|
||||
|
||||
}
|
||||
13
Source/ThirdParty/msdfgen/msdfgen/msdfgen-config.h
vendored
Normal file
13
Source/ThirdParty/msdfgen/msdfgen/msdfgen-config.h
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MSDFGEN_PUBLIC
|
||||
#define MSDFGEN_EXT_PUBLIC
|
||||
|
||||
#define MSDFGEN_VERSION 1.12.1
|
||||
#define MSDFGEN_VERSION_MAJOR 1
|
||||
#define MSDFGEN_VERSION_MINOR 12
|
||||
#define MSDFGEN_VERSION_REVISION 1
|
||||
#define MSDFGEN_COPYRIGHT_YEAR 2025
|
||||
|
||||
#define MSDFGEN_USE_CPP11
|
||||
78
Source/ThirdParty/msdfgen/msdfgen/msdfgen.h
vendored
Normal file
78
Source/ThirdParty/msdfgen/msdfgen/msdfgen.h
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR
|
||||
* ---------------------------------------------
|
||||
* A utility by Viktor Chlumsky, (c) 2014 - 2025
|
||||
*
|
||||
* The technique used to generate multi-channel distance fields in this code
|
||||
* has been developed by Viktor Chlumsky in 2014 for his master's thesis,
|
||||
* "Shape Decomposition for Multi-Channel Distance Fields". It provides improved
|
||||
* quality of sharp corners in glyphs and other 2D shapes compared to monochrome
|
||||
* distance fields. To reconstruct an image of the shape, apply the median of three
|
||||
* operation on the triplet of sampled signed distance values.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "core/base.h"
|
||||
#include "core/arithmetics.hpp"
|
||||
#include "core/Vector2.hpp"
|
||||
#include "core/Range.hpp"
|
||||
#include "core/Projection.h"
|
||||
#include "core/DistanceMapping.h"
|
||||
#include "core/SDFTransformation.h"
|
||||
#include "core/Scanline.h"
|
||||
#include "core/Shape.h"
|
||||
#include "core/BitmapRef.hpp"
|
||||
#include "core/Bitmap.h"
|
||||
#include "core/bitmap-interpolation.hpp"
|
||||
#include "core/pixel-conversion.hpp"
|
||||
#include "core/edge-coloring.h"
|
||||
#include "core/generator-config.h"
|
||||
#include "core/msdf-error-correction.h"
|
||||
#include "core/render-sdf.h"
|
||||
#include "core/rasterization.h"
|
||||
#include "core/sdf-error-estimation.h"
|
||||
#include "core/save-bmp.h"
|
||||
#include "core/save-tiff.h"
|
||||
#include "core/save-rgba.h"
|
||||
#include "core/save-fl32.h"
|
||||
#include "core/shape-description.h"
|
||||
#include "core/export-svg.h"
|
||||
|
||||
namespace msdfgen {
|
||||
|
||||
/// Generates a conventional single-channel signed distance field.
|
||||
void generateSDF(const BitmapRef<float, 1> &output, const Shape &shape, const SDFTransformation &transformation, const GeneratorConfig &config = GeneratorConfig());
|
||||
|
||||
/// Generates a single-channel signed perpendicular distance field.
|
||||
void generatePSDF(const BitmapRef<float, 1> &output, const Shape &shape, const SDFTransformation &transformation, const GeneratorConfig &config = GeneratorConfig());
|
||||
|
||||
/// Generates a multi-channel signed distance field. Edge colors must be assigned first! (See edgeColoringSimple)
|
||||
void generateMSDF(const BitmapRef<float, 3> &output, const Shape &shape, const SDFTransformation &transformation, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
|
||||
|
||||
/// Generates a multi-channel signed distance field with true distance in the alpha channel. Edge colors must be assigned first.
|
||||
void generateMTSDF(const BitmapRef<float, 4> &output, const Shape &shape, const SDFTransformation &transformation, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
|
||||
|
||||
// Old version of the function API's kept for backwards compatibility
|
||||
void generateSDF(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, Range range, const GeneratorConfig &config = GeneratorConfig());
|
||||
void generatePSDF(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, Range range, const GeneratorConfig &config = GeneratorConfig());
|
||||
void generatePseudoSDF(const BitmapRef<float, 1> &output, const Shape &shape, const Projection &projection, Range range, const GeneratorConfig &config = GeneratorConfig());
|
||||
void generateMSDF(const BitmapRef<float, 3> &output, const Shape &shape, const Projection &projection, Range range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
|
||||
void generateMTSDF(const BitmapRef<float, 4> &output, const Shape &shape, const Projection &projection, Range range, const MSDFGeneratorConfig &config = MSDFGeneratorConfig());
|
||||
|
||||
void generateSDF(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
|
||||
void generatePSDF(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
|
||||
void generatePseudoSDF(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, bool overlapSupport = true);
|
||||
void generateMSDF(const BitmapRef<float, 3> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, const ErrorCorrectionConfig &errorCorrectionConfig = ErrorCorrectionConfig(), bool overlapSupport = true);
|
||||
void generateMTSDF(const BitmapRef<float, 4> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, const ErrorCorrectionConfig &errorCorrectionConfig = ErrorCorrectionConfig(), bool overlapSupport = true);
|
||||
|
||||
// Original simpler versions of the previous functions, which work well under normal circumstances, but cannot deal with overlapping contours.
|
||||
void generateSDF_legacy(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate);
|
||||
void generatePSDF_legacy(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate);
|
||||
void generatePseudoSDF_legacy(const BitmapRef<float, 1> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate);
|
||||
void generateMSDF_legacy(const BitmapRef<float, 3> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, ErrorCorrectionConfig errorCorrectionConfig = ErrorCorrectionConfig());
|
||||
void generateMTSDF_legacy(const BitmapRef<float, 4> &output, const Shape &shape, Range range, const Vector2 &scale, const Vector2 &translate, ErrorCorrectionConfig errorCorrectionConfig = ErrorCorrectionConfig());
|
||||
|
||||
}
|
||||
13
Source/ThirdParty/msdfgen/msdfgen/msdfgen/msdfgen-config.h
vendored
Normal file
13
Source/ThirdParty/msdfgen/msdfgen/msdfgen/msdfgen-config.h
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MSDFGEN_PUBLIC
|
||||
#define MSDFGEN_EXT_PUBLIC
|
||||
|
||||
#define MSDFGEN_VERSION 1.12.1
|
||||
#define MSDFGEN_VERSION_MAJOR 1
|
||||
#define MSDFGEN_VERSION_MINOR 12
|
||||
#define MSDFGEN_VERSION_REVISION 1
|
||||
#define MSDFGEN_COPYRIGHT_YEAR 2025
|
||||
|
||||
#define MSDFGEN_USE_CPP11
|
||||
126
Source/Tools/Flax.Build/Deps/Dependencies/msdfgen.cs
Normal file
126
Source/Tools/Flax.Build/Deps/Dependencies/msdfgen.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Flax.Build;
|
||||
|
||||
namespace Flax.Deps.Dependencies
|
||||
{
|
||||
/// <summary>
|
||||
/// Official Open Asset Import Library Repository. Loads 40+ 3D file formats into one unified and clean data structure. http://www.assimp.org
|
||||
/// </summary>
|
||||
/// <seealso cref="Flax.Deps.Dependency" />
|
||||
class msdfgen : Dependency
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override TargetPlatform[] Platforms
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (BuildPlatform)
|
||||
{
|
||||
case TargetPlatform.Windows:
|
||||
return new[]
|
||||
{
|
||||
TargetPlatform.Windows,
|
||||
};
|
||||
case TargetPlatform.Linux:
|
||||
return new[]
|
||||
{
|
||||
TargetPlatform.Linux,
|
||||
};
|
||||
case TargetPlatform.Mac:
|
||||
return new[]
|
||||
{
|
||||
TargetPlatform.Mac,
|
||||
};
|
||||
default: return new TargetPlatform[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Build(BuildOptions options)
|
||||
{
|
||||
var root = options.IntermediateFolder;
|
||||
string includeDir = null;
|
||||
var filesToKeep = new[]
|
||||
{
|
||||
"msdfgen.Build.cs",
|
||||
};
|
||||
var args = new string[]
|
||||
{
|
||||
"-DMSDFGEN_USE_VCPKG=OFF",
|
||||
"-DMSDFGEN_CORE_ONLY=ON",
|
||||
"-DMSDFGEN_DYNAMIC_RUNTIME=ON",
|
||||
"-DMSDFGEN_USE_SKIA=OFF",
|
||||
"-DBUILD_SHARED_LIBS=OFF",
|
||||
"-DMSDFGEN_INSTALL=ON"
|
||||
};
|
||||
var cmakeArgs = string.Join(" ", args);
|
||||
|
||||
// Get the source
|
||||
CloneGitRepoSingleBranch(root, "https://github.com/Chlumsky/msdfgen.git", "master", "a4dafbac1c29021613fbc89768963f3a7e2105aa");
|
||||
|
||||
foreach (var platform in options.Platforms)
|
||||
{
|
||||
BuildStarted(platform);
|
||||
switch (platform)
|
||||
{
|
||||
case TargetPlatform.Windows:
|
||||
{
|
||||
var configuration = "Release";
|
||||
|
||||
// Build for Windows
|
||||
File.Delete(Path.Combine(root, "CMakeCache.txt"));
|
||||
foreach (var architecture in new[] { TargetArchitecture.x64, TargetArchitecture.ARM64 })
|
||||
{
|
||||
var buildDir = Path.Combine(root, "build-" + architecture);
|
||||
var installDir = Path.Combine(root, "install-" + architecture);
|
||||
SetupDirectory(buildDir, true);
|
||||
RunCmake(root, platform, architecture, $"-B\"{buildDir}\" " + cmakeArgs);
|
||||
BuildCmake(buildDir);
|
||||
Utilities.Run("cmake", $"--install {buildDir} --prefix {installDir} --config {configuration}", null, root, Utilities.RunOptions.DefaultTool);
|
||||
var depsFolder = GetThirdPartyFolder(options, platform, architecture);
|
||||
Utilities.FileCopy(Path.Combine(installDir, "lib", "msdfgen-core.lib"), Path.Combine(depsFolder, "msdfgen-core.lib"));
|
||||
// This will be set multiple times, but the headers are the same anyway.
|
||||
includeDir = Path.Combine(installDir, "include");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case TargetPlatform.Linux:
|
||||
{
|
||||
// todo
|
||||
break;
|
||||
}
|
||||
case TargetPlatform.Mac:
|
||||
{
|
||||
// todo
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Backup files
|
||||
var dstIncludePath = Path.Combine(options.ThirdPartyFolder, "msdfgen");
|
||||
foreach (var filename in filesToKeep)
|
||||
{
|
||||
var src = Path.Combine(dstIncludePath, filename);
|
||||
var dst = Path.Combine(options.IntermediateFolder, filename + ".tmp");
|
||||
Utilities.FileCopy(src, dst);
|
||||
}
|
||||
|
||||
// Deploy header files and license
|
||||
SetupDirectory(dstIncludePath, true);
|
||||
Utilities.FileCopy(Path.Combine(root, "LICENSE.txt"), Path.Combine(dstIncludePath, "LICENSE.txt"));
|
||||
Utilities.DirectoryCopy(includeDir, dstIncludePath, true, true);
|
||||
foreach (var filename in filesToKeep)
|
||||
{
|
||||
var src = Path.Combine(options.IntermediateFolder, filename + ".tmp");
|
||||
var dst = Path.Combine(dstIncludePath, filename);
|
||||
Utilities.FileCopy(src, dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user