diff --git a/modules/msdfgen/SCsub b/modules/msdfgen/SCsub index 0c269bc7f498..f4316a74e783 100644 --- a/modules/msdfgen/SCsub +++ b/modules/msdfgen/SCsub @@ -20,8 +20,6 @@ if env["builtin_msdfgen"]: "core/Projection.cpp", "core/Scanline.cpp", "core/Shape.cpp", - "core/SignedDistance.cpp", - "core/Vector2.cpp", "core/contour-combiners.cpp", "core/edge-coloring.cpp", "core/edge-segments.cpp", @@ -36,6 +34,7 @@ if env["builtin_msdfgen"]: ] thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources] + env_msdfgen.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")]) env_msdfgen.Prepend(CPPPATH=["#thirdparty/freetype/include", "#thirdparty/msdfgen", "#thirdparty/nanosvg"]) lib = env_msdfgen.add_library("msdfgen_builtin", thirdparty_sources) diff --git a/modules/text_server_adv/SCsub b/modules/text_server_adv/SCsub index 6b53353ec9f0..b04ad77bc97b 100644 --- a/modules/text_server_adv/SCsub +++ b/modules/text_server_adv/SCsub @@ -531,6 +531,7 @@ module_obj = [] if env["builtin_msdfgen"] and msdfgen_enabled: # Treat msdfgen headers as system headers to avoid raising warnings. Not supported on MSVC. + env_text_server_adv.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")]) if not env.msvc: env_text_server_adv.Append(CPPFLAGS=["-isystem", Dir("#thirdparty/msdfgen").path]) else: diff --git a/modules/text_server_adv/gdextension_build/SConstruct b/modules/text_server_adv/gdextension_build/SConstruct index cd4331b60e24..1f27f5ade982 100644 --- a/modules/text_server_adv/gdextension_build/SConstruct +++ b/modules/text_server_adv/gdextension_build/SConstruct @@ -133,8 +133,6 @@ if env["msdfgen_enabled"] and env["freetype_enabled"]: "core/Projection.cpp", "core/Scanline.cpp", "core/Shape.cpp", - "core/SignedDistance.cpp", - "core/Vector2.cpp", "core/contour-combiners.cpp", "core/edge-coloring.cpp", "core/edge-segments.cpp", @@ -149,8 +147,10 @@ if env["msdfgen_enabled"] and env["freetype_enabled"]: ] thirdparty_msdfgen_sources = [thirdparty_msdfgen_dir + file for file in thirdparty_msdfgen_sources] + env_msdfgen.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")]) env_msdfgen.Append(CPPPATH=["../../../thirdparty/freetype/include", "../../../thirdparty/msdfgen"]) env.Append(CPPPATH=["../../../thirdparty/msdfgen"]) + env.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")]) env.Append(CPPDEFINES=["MODULE_MSDFGEN_ENABLED"]) lib = env_msdfgen.Library( diff --git a/modules/text_server_adv/text_server_adv.cpp b/modules/text_server_adv/text_server_adv.cpp index bb198c9c2b5e..8178978fe2d2 100644 --- a/modules/text_server_adv/text_server_adv.cpp +++ b/modules/text_server_adv/text_server_adv.cpp @@ -67,10 +67,16 @@ using namespace godot; // Thirdparty headers. #ifdef MODULE_MSDFGEN_ENABLED +#ifdef _MSC_VER +#pragma warning(disable : 4458) +#endif #include #include #include #include +#ifdef _MSC_VER +#pragma warning(default : 4458) +#endif #endif #ifdef MODULE_SVG_ENABLED diff --git a/modules/text_server_fb/SCsub b/modules/text_server_fb/SCsub index e808864512b6..fc0a8727c612 100644 --- a/modules/text_server_fb/SCsub +++ b/modules/text_server_fb/SCsub @@ -17,6 +17,7 @@ if "svg" in env.module_list: if env["builtin_msdfgen"] and msdfgen_enabled: # Treat msdfgen headers as system headers to avoid raising warnings. Not supported on MSVC. + env_text_server_fb.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")]) if not env.msvc: env_text_server_fb.Append(CPPFLAGS=["-isystem", Dir("#thirdparty/msdfgen").path]) else: diff --git a/modules/text_server_fb/gdextension_build/SConstruct b/modules/text_server_fb/gdextension_build/SConstruct index 0efced0bfc11..29801ede8eaa 100644 --- a/modules/text_server_fb/gdextension_build/SConstruct +++ b/modules/text_server_fb/gdextension_build/SConstruct @@ -144,8 +144,10 @@ if env["msdfgen_enabled"] and env["freetype_enabled"]: ] thirdparty_msdfgen_sources = [thirdparty_msdfgen_dir + file for file in thirdparty_msdfgen_sources] + env_msdfgen.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")]) env_msdfgen.Append(CPPPATH=["../../../thirdparty/freetype/include", "../../../thirdparty/msdfgen"]) env.Append(CPPPATH=["../../../thirdparty/msdfgen"]) + env.Append(CPPDEFINES=[("MSDFGEN_PUBLIC", "")]) env.Append(CPPDEFINES=["MODULE_MSDFGEN_ENABLED"]) lib = env_msdfgen.Library( diff --git a/modules/text_server_fb/text_server_fb.cpp b/modules/text_server_fb/text_server_fb.cpp index edf34d455012..4c0ed084d8c8 100644 --- a/modules/text_server_fb/text_server_fb.cpp +++ b/modules/text_server_fb/text_server_fb.cpp @@ -59,10 +59,16 @@ using namespace godot; // Thirdparty headers. #ifdef MODULE_MSDFGEN_ENABLED +#ifdef _MSC_VER +#pragma warning(disable : 4458) +#endif #include #include #include #include +#ifdef _MSC_VER +#pragma warning(default : 4458) +#endif #endif #ifdef MODULE_SVG_ENABLED diff --git a/thirdparty/README.md b/thirdparty/README.md index a36a8f209f17..2c9bc36545a3 100644 --- a/thirdparty/README.md +++ b/thirdparty/README.md @@ -390,7 +390,7 @@ Files extracted from upstream source: ## icu4c - Upstream: https://github.com/unicode-org/icu -- Version: 74.1 (9edac7b78327a1cb58db29e2714b15f9fa14e4d7, 2023) +- Version: 74.2 (2d029329c82c7792b985024b2bdab5fc7278fbc8, 2023) - License: Unicode Files extracted from upstream source: @@ -690,7 +690,7 @@ Collection of single-file libraries used in Godot components. ## msdfgen - Upstream: https://github.com/Chlumsky/msdfgen -- Version: 1.10 (64a91eec3ca3787e6f78b4c99fcd3052ad3e37c0, 2021) +- Version: 1.11 (f12d7ca00091a632a289865b85c3f2e0bfc6542d, 2023) - License: MIT Files extracted from the upstream source: diff --git a/thirdparty/icu4c/common/unicode/uvernum.h b/thirdparty/icu4c/common/unicode/uvernum.h index 9fc98e738070..1cdf8912f94b 100644 --- a/thirdparty/icu4c/common/unicode/uvernum.h +++ b/thirdparty/icu4c/common/unicode/uvernum.h @@ -59,7 +59,7 @@ * This value will change in the subsequent releases of ICU * @stable ICU 2.6 */ -#define U_ICU_VERSION_MINOR_NUM 1 +#define U_ICU_VERSION_MINOR_NUM 2 /** The current ICU patchlevel version as an integer. * This value will change in the subsequent releases of ICU @@ -132,7 +132,7 @@ * This value will change in the subsequent releases of ICU * @stable ICU 2.4 */ -#define U_ICU_VERSION "74.1" +#define U_ICU_VERSION "74.2" /** * The current ICU library major version number as a string, for library name suffixes. @@ -151,7 +151,7 @@ /** Data version in ICU4C. * @internal ICU 4.4 Internal Use Only **/ -#define U_ICU_DATA_VERSION "74.1" +#define U_ICU_DATA_VERSION "74.2" #endif /* U_HIDE_INTERNAL_API */ /*=========================================================================== diff --git a/thirdparty/icu4c/icudt74l.dat b/thirdparty/icu4c/icudt74l.dat index 8576067fd0f4..e4ce73e23c84 100644 Binary files a/thirdparty/icu4c/icudt74l.dat and b/thirdparty/icu4c/icudt74l.dat differ diff --git a/thirdparty/msdfgen/LICENSE.txt b/thirdparty/msdfgen/LICENSE.txt index 9757001664ac..69054bd2e182 100644 --- a/thirdparty/msdfgen/LICENSE.txt +++ b/thirdparty/msdfgen/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2016 - 2022 Viktor Chlumsky +Copyright (c) 2016 - 2023 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 diff --git a/thirdparty/msdfgen/core/Bitmap.h b/thirdparty/msdfgen/core/Bitmap.h index 14407d6c3493..9a08749f47f0 100644 --- a/thirdparty/msdfgen/core/Bitmap.h +++ b/thirdparty/msdfgen/core/Bitmap.h @@ -18,17 +18,17 @@ class Bitmap { Bitmap(Bitmap &&orig); #endif ~Bitmap(); - Bitmap & operator=(const BitmapConstRef &orig); - Bitmap & operator=(const Bitmap &orig); + Bitmap &operator=(const BitmapConstRef &orig); + Bitmap &operator=(const Bitmap &orig); #ifdef MSDFGEN_USE_CPP11 - Bitmap & operator=(Bitmap &&orig); + Bitmap &operator=(Bitmap &&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; + 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; diff --git a/thirdparty/msdfgen/core/Bitmap.hpp b/thirdparty/msdfgen/core/Bitmap.hpp index cb16cac8d4f7..9404357788da 100644 --- a/thirdparty/msdfgen/core/Bitmap.hpp +++ b/thirdparty/msdfgen/core/Bitmap.hpp @@ -40,7 +40,7 @@ Bitmap::~Bitmap() { } template -Bitmap & Bitmap::operator=(const BitmapConstRef &orig) { +Bitmap &Bitmap::operator=(const BitmapConstRef &orig) { if (pixels != orig.pixels) { delete [] pixels; w = orig.width, h = orig.height; @@ -51,7 +51,7 @@ Bitmap & Bitmap::operator=(const BitmapConstRef &orig) { } template -Bitmap & Bitmap::operator=(const Bitmap &orig) { +Bitmap &Bitmap::operator=(const Bitmap &orig) { if (this != &orig) { delete [] pixels; w = orig.w, h = orig.h; @@ -63,7 +63,7 @@ Bitmap & Bitmap::operator=(const Bitmap &orig) { #ifdef MSDFGEN_USE_CPP11 template -Bitmap & Bitmap::operator=(Bitmap &&orig) { +Bitmap &Bitmap::operator=(Bitmap &&orig) { if (this != &orig) { delete [] pixels; pixels = orig.pixels; @@ -85,12 +85,12 @@ int Bitmap::height() const { } template -T * Bitmap::operator()(int x, int y) { +T *Bitmap::operator()(int x, int y) { return pixels+N*(w*y+x); } template -const T * Bitmap::operator()(int x, int y) const { +const T *Bitmap::operator()(int x, int y) const { return pixels+N*(w*y+x); } diff --git a/thirdparty/msdfgen/core/BitmapRef.hpp b/thirdparty/msdfgen/core/BitmapRef.hpp index 6f9620dcdfd7..cb17f95dcb89 100644 --- a/thirdparty/msdfgen/core/BitmapRef.hpp +++ b/thirdparty/msdfgen/core/BitmapRef.hpp @@ -1,12 +1,10 @@ #pragma once -#include +#include "base.h" namespace msdfgen { -typedef unsigned char byte; - /// Reference to a 2D image bitmap or a buffer acting as one. Pixel storage not owned or managed by the object. template struct BitmapRef { @@ -17,7 +15,7 @@ struct BitmapRef { 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 { + inline T *operator()(int x, int y) const { return pixels+N*(width*y+x); } @@ -34,7 +32,7 @@ struct BitmapConstRef { inline BitmapConstRef(const T *pixels, int width, int height) : pixels(pixels), width(width), height(height) { } inline BitmapConstRef(const BitmapRef &orig) : pixels(orig.pixels), width(orig.width), height(orig.height) { } - inline const T * operator()(int x, int y) const { + inline const T *operator()(int x, int y) const { return pixels+N*(width*y+x); } diff --git a/thirdparty/msdfgen/core/Contour.cpp b/thirdparty/msdfgen/core/Contour.cpp index ca80d3c55a24..57293dc58be0 100644 --- a/thirdparty/msdfgen/core/Contour.cpp +++ b/thirdparty/msdfgen/core/Contour.cpp @@ -19,7 +19,7 @@ void Contour::addEdge(EdgeHolder &&edge) { } #endif -EdgeHolder & Contour::addEdge() { +EdgeHolder &Contour::addEdge() { edges.resize(edges.size()+1); return edges.back(); } diff --git a/thirdparty/msdfgen/core/Contour.h b/thirdparty/msdfgen/core/Contour.h index f79b26958223..4cae48fad75d 100644 --- a/thirdparty/msdfgen/core/Contour.h +++ b/thirdparty/msdfgen/core/Contour.h @@ -19,7 +19,7 @@ class Contour { void addEdge(EdgeHolder &&edge); #endif /// Creates a new edge in the contour and returns its reference. - EdgeHolder & addEdge(); + 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. diff --git a/thirdparty/msdfgen/core/EdgeColor.h b/thirdparty/msdfgen/core/EdgeColor.h index 9d49a5a89ef0..5d3730c9a65f 100644 --- a/thirdparty/msdfgen/core/EdgeColor.h +++ b/thirdparty/msdfgen/core/EdgeColor.h @@ -1,6 +1,8 @@ #pragma once +#include "base.h" + namespace msdfgen { /// Edge color specifies which color channels an edge belongs to. diff --git a/thirdparty/msdfgen/core/EdgeHolder.cpp b/thirdparty/msdfgen/core/EdgeHolder.cpp index 1a8c5f66e93a..cffcff46d32b 100644 --- a/thirdparty/msdfgen/core/EdgeHolder.cpp +++ b/thirdparty/msdfgen/core/EdgeHolder.cpp @@ -31,7 +31,7 @@ EdgeHolder::~EdgeHolder() { delete edgeSegment; } -EdgeHolder & EdgeHolder::operator=(const EdgeHolder &orig) { +EdgeHolder &EdgeHolder::operator=(const EdgeHolder &orig) { if (this != &orig) { delete edgeSegment; edgeSegment = orig.edgeSegment ? orig.edgeSegment->clone() : NULL; @@ -40,7 +40,7 @@ EdgeHolder & EdgeHolder::operator=(const EdgeHolder &orig) { } #ifdef MSDFGEN_USE_CPP11 -EdgeHolder & EdgeHolder::operator=(EdgeHolder &&orig) { +EdgeHolder &EdgeHolder::operator=(EdgeHolder &&orig) { if (this != &orig) { delete edgeSegment; edgeSegment = orig.edgeSegment; @@ -50,19 +50,19 @@ EdgeHolder & EdgeHolder::operator=(EdgeHolder &&orig) { } #endif -EdgeSegment & EdgeHolder::operator*() { +EdgeSegment &EdgeHolder::operator*() { return *edgeSegment; } -const EdgeSegment & EdgeHolder::operator*() const { +const EdgeSegment &EdgeHolder::operator*() const { return *edgeSegment; } -EdgeSegment * EdgeHolder::operator->() { +EdgeSegment *EdgeHolder::operator->() { return edgeSegment; } -const EdgeSegment * EdgeHolder::operator->() const { +const EdgeSegment *EdgeHolder::operator->() const { return edgeSegment; } diff --git a/thirdparty/msdfgen/core/EdgeHolder.h b/thirdparty/msdfgen/core/EdgeHolder.h index c4c5be76168f..50a59b21891b 100644 --- a/thirdparty/msdfgen/core/EdgeHolder.h +++ b/thirdparty/msdfgen/core/EdgeHolder.h @@ -22,14 +22,14 @@ class EdgeHolder { EdgeHolder(EdgeHolder &&orig); #endif ~EdgeHolder(); - EdgeHolder & operator=(const EdgeHolder &orig); + EdgeHolder &operator=(const EdgeHolder &orig); #ifdef MSDFGEN_USE_CPP11 - EdgeHolder & operator=(EdgeHolder &&orig); + EdgeHolder &operator=(EdgeHolder &&orig); #endif - EdgeSegment & operator*(); - const EdgeSegment & operator*() const; - EdgeSegment * operator->(); - const EdgeSegment * operator->() const; + EdgeSegment &operator*(); + const EdgeSegment &operator*() const; + EdgeSegment *operator->(); + const EdgeSegment *operator->() const; operator EdgeSegment *(); operator const EdgeSegment *() const; diff --git a/thirdparty/msdfgen/core/MSDFErrorCorrection.cpp b/thirdparty/msdfgen/core/MSDFErrorCorrection.cpp index 7918597fd22e..9a5cefe12870 100644 --- a/thirdparty/msdfgen/core/MSDFErrorCorrection.cpp +++ b/thirdparty/msdfgen/core/MSDFErrorCorrection.cpp @@ -19,8 +19,8 @@ namespace msdfgen { #define CLASSIFIER_FLAG_CANDIDATE 0x01 #define CLASSIFIER_FLAG_ARTIFACT 0x02 -const double ErrorCorrectionConfig::defaultMinDeviationRatio = 1.11111111111111111; -const double ErrorCorrectionConfig::defaultMinImproveRatio = 1.11111111111111111; +MSDFGEN_PUBLIC const double ErrorCorrectionConfig::defaultMinDeviationRatio = 1.11111111111111111; +MSDFGEN_PUBLIC const double ErrorCorrectionConfig::defaultMinImproveRatio = 1.11111111111111111; /// The base artifact classifier recognizes artifacts based on the contents of the SDF alone. class BaseArtifactClassifier { @@ -317,7 +317,7 @@ static bool hasDiagonalArtifactInner(const ArtifactClassifier &artifactClassifie em[0] = am, em[1] = dm; tEnd[tEx0 > t[i]] = tEx0; em[tEx0 > t[i]] = interpolatedMedian(a, l, q, tEx0); - rangeFlags |= artifactClassifier.rangeTest(tEnd[0], tEnd[1], t[i], am, dm, xm); + rangeFlags |= artifactClassifier.rangeTest(tEnd[0], tEnd[1], t[i], em[0], em[1], xm); } // tEx1 if (tEx1 > 0 && tEx1 < 1) { @@ -325,7 +325,7 @@ static bool hasDiagonalArtifactInner(const ArtifactClassifier &artifactClassifie em[0] = am, em[1] = dm; tEnd[tEx1 > t[i]] = tEx1; em[tEx1 > t[i]] = interpolatedMedian(a, l, q, tEx1); - rangeFlags |= artifactClassifier.rangeTest(tEnd[0], tEnd[1], t[i], am, dm, xm); + rangeFlags |= artifactClassifier.rangeTest(tEnd[0], tEnd[1], t[i], em[0], em[1], xm); } if (artifactClassifier.evaluate(t[i], xm, rangeFlags)) return true; diff --git a/thirdparty/msdfgen/core/Projection.h b/thirdparty/msdfgen/core/Projection.h index 7cdb1c307a6f..3c457776acf5 100644 --- a/thirdparty/msdfgen/core/Projection.h +++ b/thirdparty/msdfgen/core/Projection.h @@ -1,7 +1,7 @@ #pragma once -#include "Vector2.h" +#include "Vector2.hpp" namespace msdfgen { diff --git a/thirdparty/msdfgen/core/Scanline.cpp b/thirdparty/msdfgen/core/Scanline.cpp index 8e5352dbf680..7407be41b567 100644 --- a/thirdparty/msdfgen/core/Scanline.cpp +++ b/thirdparty/msdfgen/core/Scanline.cpp @@ -1,7 +1,7 @@ #include "Scanline.h" -#include +#include #include "arithmetics.hpp" namespace msdfgen { diff --git a/thirdparty/msdfgen/core/Scanline.h b/thirdparty/msdfgen/core/Scanline.h index 9c8f34044bee..c0abc6864293 100644 --- a/thirdparty/msdfgen/core/Scanline.h +++ b/thirdparty/msdfgen/core/Scanline.h @@ -2,6 +2,7 @@ #pragma once #include +#include "base.h" namespace msdfgen { diff --git a/thirdparty/msdfgen/core/Shape.cpp b/thirdparty/msdfgen/core/Shape.cpp index 8d6f47c80710..cf99bd0f0c00 100644 --- a/thirdparty/msdfgen/core/Shape.cpp +++ b/thirdparty/msdfgen/core/Shape.cpp @@ -1,7 +1,7 @@ #include "Shape.h" -#include +#include #include "arithmetics.hpp" namespace msdfgen { @@ -18,7 +18,7 @@ void Shape::addContour(Contour &&contour) { } #endif -Contour & Shape::addContour() { +Contour &Shape::addContour() { contours.resize(contours.size()+1); return contours.back(); } @@ -40,15 +40,12 @@ bool Shape::validate() const { } static void deconvergeEdge(EdgeHolder &edgeHolder, int param) { - { - const QuadraticSegment *quadraticSegment = dynamic_cast(&*edgeHolder); - if (quadraticSegment) - edgeHolder = quadraticSegment->convertToCubic(); - } - { - CubicSegment *cubicSegment = dynamic_cast(&*edgeHolder); - if (cubicSegment) - cubicSegment->deconverge(param, MSDFGEN_DECONVERGENCE_FACTOR); + switch (edgeHolder->type()) { + case (int) QuadraticSegment::EDGE_TYPE: + edgeHolder = static_cast(&*edgeHolder)->convertToCubic(); + // fallthrough + case (int) CubicSegment::EDGE_TYPE: + static_cast(&*edgeHolder)->deconverge(param, MSDFGEN_DECONVERGENCE_FACTOR); } } @@ -162,16 +159,18 @@ void Shape::orientContours() { } } } - qsort(&intersections[0], intersections.size(), sizeof(Intersection), &Intersection::compare); - // Disqualify multiple intersections - for (int j = 1; j < (int) intersections.size(); ++j) - if (intersections[j].x == intersections[j-1].x) - intersections[j].direction = intersections[j-1].direction = 0; - // Inspect scanline and deduce orientations of intersected contours - for (int j = 0; j < (int) intersections.size(); ++j) - if (intersections[j].direction) - orientations[intersections[j].contourIndex] += 2*((j&1)^(intersections[j].direction > 0))-1; - intersections.clear(); + if (!intersections.empty()) { + qsort(&intersections[0], intersections.size(), sizeof(Intersection), &Intersection::compare); + // Disqualify multiple intersections + for (int j = 1; j < (int) intersections.size(); ++j) + if (intersections[j].x == intersections[j-1].x) + intersections[j].direction = intersections[j-1].direction = 0; + // Inspect scanline and deduce orientations of intersected contours + for (int j = 0; j < (int) intersections.size(); ++j) + if (intersections[j].direction) + orientations[intersections[j].contourIndex] += 2*((j&1)^(intersections[j].direction > 0))-1; + intersections.clear(); + } } } // Reverse contours that have the opposite orientation diff --git a/thirdparty/msdfgen/core/Shape.h b/thirdparty/msdfgen/core/Shape.h index 7539921ce7ea..fd9222dbc4e9 100644 --- a/thirdparty/msdfgen/core/Shape.h +++ b/thirdparty/msdfgen/core/Shape.h @@ -32,7 +32,7 @@ class Shape { void addContour(Contour &&contour); #endif /// Adds a blank contour and returns its reference. - Contour & addContour(); + Contour &addContour(); /// Normalizes the shape geometry for distance field generation. void normalize(); /// Performs basic checks to determine if the object represents a valid shape. diff --git a/thirdparty/msdfgen/core/ShapeDistanceFinder.h b/thirdparty/msdfgen/core/ShapeDistanceFinder.h index 57df8d8e7263..d8a584f64546 100644 --- a/thirdparty/msdfgen/core/ShapeDistanceFinder.h +++ b/thirdparty/msdfgen/core/ShapeDistanceFinder.h @@ -2,7 +2,7 @@ #pragma once #include -#include "Vector2.h" +#include "Vector2.hpp" #include "edge-selectors.h" #include "contour-combiners.h" diff --git a/thirdparty/msdfgen/core/ShapeDistanceFinder.hpp b/thirdparty/msdfgen/core/ShapeDistanceFinder.hpp index 028738e5c32b..07fb5cdc0e6a 100644 --- a/thirdparty/msdfgen/core/ShapeDistanceFinder.hpp +++ b/thirdparty/msdfgen/core/ShapeDistanceFinder.hpp @@ -9,7 +9,11 @@ ShapeDistanceFinder::ShapeDistanceFinder(const Shape &shape) : template typename ShapeDistanceFinder::DistanceType ShapeDistanceFinder::distance(const Point2 &origin) { contourCombiner.reset(origin); - typename ContourCombiner::EdgeSelectorType::EdgeCache *edgeCache = &shapeEdgeCache[0]; +#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::const_iterator contour = shape.contours.begin(); contour != shape.contours.end(); ++contour) { if (!contour->edges.empty()) { diff --git a/thirdparty/msdfgen/core/SignedDistance.cpp b/thirdparty/msdfgen/core/SignedDistance.cpp deleted file mode 100644 index be956d953e14..000000000000 --- a/thirdparty/msdfgen/core/SignedDistance.cpp +++ /dev/null @@ -1,29 +0,0 @@ - -#include "SignedDistance.h" - -#include -#include - -namespace msdfgen { - -SignedDistance::SignedDistance() : distance(-DBL_MAX), dot(1) { } - -SignedDistance::SignedDistance(double dist, double d) : distance(dist), dot(d) { } - -bool operator<(SignedDistance a, SignedDistance b) { - return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot < b.dot); -} - -bool operator>(SignedDistance a, SignedDistance b) { - return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot > b.dot); -} - -bool operator<=(SignedDistance a, SignedDistance b) { - return fabs(a.distance) < fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot <= b.dot); -} - -bool operator>=(SignedDistance a, SignedDistance b) { - return fabs(a.distance) > fabs(b.distance) || (fabs(a.distance) == fabs(b.distance) && a.dot >= b.dot); -} - -} diff --git a/thirdparty/msdfgen/core/SignedDistance.h b/thirdparty/msdfgen/core/SignedDistance.h deleted file mode 100644 index 91fee97600af..000000000000 --- a/thirdparty/msdfgen/core/SignedDistance.h +++ /dev/null @@ -1,23 +0,0 @@ - -#pragma once - -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; - - SignedDistance(); - SignedDistance(double dist, double d); - - friend bool operator<(SignedDistance a, SignedDistance b); - friend bool operator>(SignedDistance a, SignedDistance b); - friend bool operator<=(SignedDistance a, SignedDistance b); - friend bool operator>=(SignedDistance a, SignedDistance b); - -}; - -} diff --git a/thirdparty/msdfgen/core/SignedDistance.hpp b/thirdparty/msdfgen/core/SignedDistance.hpp new file mode 100644 index 000000000000..62e73c03aa92 --- /dev/null +++ b/thirdparty/msdfgen/core/SignedDistance.hpp @@ -0,0 +1,38 @@ + +#pragma once + +#include +#include +#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); +} + +} diff --git a/thirdparty/msdfgen/core/Vector2.cpp b/thirdparty/msdfgen/core/Vector2.cpp deleted file mode 100644 index 896963ff2cce..000000000000 --- a/thirdparty/msdfgen/core/Vector2.cpp +++ /dev/null @@ -1,146 +0,0 @@ - -#include "Vector2.h" - -namespace msdfgen { - -Vector2::Vector2(double val) : x(val), y(val) { } - -Vector2::Vector2(double x, double y) : x(x), y(y) { } - -void Vector2::reset() { - x = 0, y = 0; -} - -void Vector2::set(double x, double y) { - Vector2::x = x, Vector2::y = y; -} - -double Vector2::length() const { - return sqrt(x*x+y*y); -} - -double Vector2::direction() const { - return atan2(y, x); -} - -Vector2 Vector2::normalize(bool allowZero) const { - double len = length(); - if (len == 0) - return Vector2(0, !allowZero); - return Vector2(x/len, y/len); -} - -Vector2 Vector2::getOrthogonal(bool polarity) const { - return polarity ? Vector2(-y, x) : Vector2(y, -x); -} - -Vector2 Vector2::getOrthonormal(bool polarity, bool allowZero) const { - double len = length(); - if (len == 0) - return polarity ? Vector2(0, !allowZero) : Vector2(0, -!allowZero); - return polarity ? Vector2(-y/len, x/len) : Vector2(y/len, -x/len); -} - -Vector2 Vector2::project(const Vector2 &vector, bool positive) const { - Vector2 n = normalize(true); - double t = dotProduct(vector, n); - if (positive && t <= 0) - return Vector2(); - return t*n; -} - -Vector2::operator const void*() const { - return x || y ? this : NULL; -} - -bool Vector2::operator!() const { - return !x && !y; -} - -bool Vector2::operator==(const Vector2 &other) const { - return x == other.x && y == other.y; -} - -bool Vector2::operator!=(const Vector2 &other) const { - return x != other.x || y != other.y; -} - -Vector2 Vector2::operator+() const { - return *this; -} - -Vector2 Vector2::operator-() const { - return Vector2(-x, -y); -} - -Vector2 Vector2::operator+(const Vector2 &other) const { - return Vector2(x+other.x, y+other.y); -} - -Vector2 Vector2::operator-(const Vector2 &other) const { - return Vector2(x-other.x, y-other.y); -} - -Vector2 Vector2::operator*(const Vector2 &other) const { - return Vector2(x*other.x, y*other.y); -} - -Vector2 Vector2::operator/(const Vector2 &other) const { - return Vector2(x/other.x, y/other.y); -} - -Vector2 Vector2::operator*(double value) const { - return Vector2(x*value, y*value); -} - -Vector2 Vector2::operator/(double value) const { - return Vector2(x/value, y/value); -} - -Vector2 & Vector2::operator+=(const Vector2 &other) { - x += other.x, y += other.y; - return *this; -} - -Vector2 & Vector2::operator-=(const Vector2 &other) { - x -= other.x, y -= other.y; - return *this; -} - -Vector2 & Vector2::operator*=(const Vector2 &other) { - x *= other.x, y *= other.y; - return *this; -} - -Vector2 & Vector2::operator/=(const Vector2 &other) { - x /= other.x, y /= other.y; - return *this; -} - -Vector2 & Vector2::operator*=(double value) { - x *= value, y *= value; - return *this; -} - -Vector2 & Vector2::operator/=(double value) { - x /= value, y /= value; - return *this; -} - -double dotProduct(const Vector2 &a, const Vector2 &b) { - return a.x*b.x+a.y*b.y; -} - -double crossProduct(const Vector2 &a, const Vector2 &b) { - return a.x*b.y-a.y*b.x; -} - -Vector2 operator*(double value, const Vector2 &vector) { - return Vector2(value*vector.x, value*vector.y); -} - -Vector2 operator/(double value, const Vector2 &vector) { - return Vector2(value/vector.x, value/vector.y); -} - -} diff --git a/thirdparty/msdfgen/core/Vector2.h b/thirdparty/msdfgen/core/Vector2.h deleted file mode 100644 index 47ca637c3d4f..000000000000 --- a/thirdparty/msdfgen/core/Vector2.h +++ /dev/null @@ -1,66 +0,0 @@ - -#pragma once - -#include -#include - -namespace msdfgen { - -/** -* A 2-dimensional euclidean vector with double precision. -* Implementation based on the Vector2 template from Artery Engine. -* @author Viktor Chlumsky -*/ -struct Vector2 { - - double x, y; - - Vector2(double val = 0); - Vector2(double x, double y); - /// Sets the vector to zero. - void reset(); - /// Sets individual elements of the vector. - void set(double x, double y); - /// Returns the vector's length. - double length() const; - /// Returns the angle of the vector in radians (atan2). - double direction() const; - /// Returns the normalized vector - one that has the same direction but unit length. - Vector2 normalize(bool allowZero = false) const; - /// Returns a vector with the same length that is orthogonal to this one. - Vector2 getOrthogonal(bool polarity = true) const; - /// Returns a vector with unit length that is orthogonal to this one. - Vector2 getOrthonormal(bool polarity = true, bool allowZero = false) const; - /// Returns a vector projected along this one. - Vector2 project(const Vector2 &vector, bool positive = false) const; - operator const void *() const; - bool operator!() const; - bool operator==(const Vector2 &other) const; - bool operator!=(const Vector2 &other) const; - Vector2 operator+() const; - Vector2 operator-() const; - Vector2 operator+(const Vector2 &other) const; - Vector2 operator-(const Vector2 &other) const; - Vector2 operator*(const Vector2 &other) const; - Vector2 operator/(const Vector2 &other) const; - Vector2 operator*(double value) const; - Vector2 operator/(double value) const; - Vector2 & operator+=(const Vector2 &other); - Vector2 & operator-=(const Vector2 &other); - Vector2 & operator*=(const Vector2 &other); - Vector2 & operator/=(const Vector2 &other); - Vector2 & operator*=(double value); - Vector2 & operator/=(double value); - /// Dot product of two vectors. - friend double dotProduct(const Vector2 &a, const Vector2 &b); - /// A special version of the cross product for 2D vectors (returns scalar value). - friend double crossProduct(const Vector2 &a, const Vector2 &b); - friend Vector2 operator*(double value, const Vector2 &vector); - friend Vector2 operator/(double value, const Vector2 &vector); - -}; - -/// A vector may also represent a point, which shall be differentiated semantically using the alias Point2. -typedef Vector2 Point2; - -} diff --git a/thirdparty/msdfgen/core/Vector2.hpp b/thirdparty/msdfgen/core/Vector2.hpp new file mode 100644 index 000000000000..0208c6149713 --- /dev/null +++ b/thirdparty/msdfgen/core/Vector2.hpp @@ -0,0 +1,167 @@ + +#pragma once + +#include +#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 x, double y) { + this->x = x, this->y = y; + } + + /// 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); +} + +} diff --git a/thirdparty/msdfgen/core/arithmetics.hpp b/thirdparty/msdfgen/core/arithmetics.hpp index 78c21d658ef8..d5158ad0d3a2 100644 --- a/thirdparty/msdfgen/core/arithmetics.hpp +++ b/thirdparty/msdfgen/core/arithmetics.hpp @@ -1,8 +1,8 @@ #pragma once -#include #include +#include "base.h" namespace msdfgen { diff --git a/thirdparty/msdfgen/core/base.h b/thirdparty/msdfgen/core/base.h new file mode 100644 index 000000000000..ab85c136e124 --- /dev/null +++ b/thirdparty/msdfgen/core/base.h @@ -0,0 +1,16 @@ + +#pragma once + +// This file needs to be included first for all MSDFgen sources + +#ifndef MSDFGEN_PUBLIC +#include +#endif + +#include + +namespace msdfgen { + +typedef unsigned char byte; + +} diff --git a/thirdparty/msdfgen/core/bitmap-interpolation.hpp b/thirdparty/msdfgen/core/bitmap-interpolation.hpp index a14b0fb534d3..ca2e48c080e2 100644 --- a/thirdparty/msdfgen/core/bitmap-interpolation.hpp +++ b/thirdparty/msdfgen/core/bitmap-interpolation.hpp @@ -2,7 +2,7 @@ #pragma once #include "arithmetics.hpp" -#include "Vector2.h" +#include "Vector2.hpp" #include "BitmapRef.hpp" namespace msdfgen { diff --git a/thirdparty/msdfgen/core/contour-combiners.cpp b/thirdparty/msdfgen/core/contour-combiners.cpp index 31f4c5da7172..bac5534810d0 100644 --- a/thirdparty/msdfgen/core/contour-combiners.cpp +++ b/thirdparty/msdfgen/core/contour-combiners.cpp @@ -33,7 +33,7 @@ void SimpleContourCombiner::reset(const Point2 &p) { } template -EdgeSelector & SimpleContourCombiner::edgeSelector(int) { +EdgeSelector &SimpleContourCombiner::edgeSelector(int) { return shapeEdgeSelector; } @@ -63,7 +63,7 @@ void OverlappingContourCombiner::reset(const Point2 &p) { } template -EdgeSelector & OverlappingContourCombiner::edgeSelector(int i) { +EdgeSelector &OverlappingContourCombiner::edgeSelector(int i) { return edgeSelectors[i]; } diff --git a/thirdparty/msdfgen/core/contour-combiners.h b/thirdparty/msdfgen/core/contour-combiners.h index 944b119aba85..04dbc342303e 100644 --- a/thirdparty/msdfgen/core/contour-combiners.h +++ b/thirdparty/msdfgen/core/contour-combiners.h @@ -16,7 +16,7 @@ class SimpleContourCombiner { explicit SimpleContourCombiner(const Shape &shape); void reset(const Point2 &p); - EdgeSelector & edgeSelector(int i); + EdgeSelector &edgeSelector(int i); DistanceType distance() const; private: @@ -34,7 +34,7 @@ class OverlappingContourCombiner { explicit OverlappingContourCombiner(const Shape &shape); void reset(const Point2 &p); - EdgeSelector & edgeSelector(int i); + EdgeSelector &edgeSelector(int i); DistanceType distance() const; private: diff --git a/thirdparty/msdfgen/core/edge-coloring.cpp b/thirdparty/msdfgen/core/edge-coloring.cpp index 6a87bba54d68..da9b03773584 100644 --- a/thirdparty/msdfgen/core/edge-coloring.cpp +++ b/thirdparty/msdfgen/core/edge-coloring.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "arithmetics.hpp" @@ -244,7 +245,7 @@ static double edgeToEdgeDistance(const EdgeSegment &a, const EdgeSegment &b, int return minDistance; } -static double splineToSplineDistance(EdgeSegment * const *edgeSegments, int aStart, int aEnd, int bStart, int bEnd, int precision) { +static double splineToSplineDistance(EdgeSegment *const *edgeSegments, int aStart, int aEnd, int bStart, int bEnd, int precision) { double minDistance = DBL_MAX; for (int ai = aStart; ai < aEnd; ++ai) for (int bi = bStart; bi < bEnd && minDistance; ++bi) { @@ -254,7 +255,7 @@ static double splineToSplineDistance(EdgeSegment * const *edgeSegments, int aSta return minDistance; } -static void colorSecondDegreeGraph(int *coloring, const int * const *edgeMatrix, int vertexCount, unsigned long long seed) { +static void colorSecondDegreeGraph(int *coloring, const int *const *edgeMatrix, int vertexCount, unsigned long long seed) { for (int i = 0; i < vertexCount; ++i) { int possibleColors = 7; for (int j = 0; j < i; ++j) { @@ -301,7 +302,7 @@ static int vertexPossibleColors(const int *coloring, const int *edgeVector, int return 7&~usedColors; } -static void uncolorSameNeighbors(std::queue &uncolored, int *coloring, const int * const *edgeMatrix, int vertex, int vertexCount) { +static void uncolorSameNeighbors(std::queue &uncolored, int *coloring, const int *const *edgeMatrix, int vertex, int vertexCount) { for (int i = vertex+1; i < vertexCount; ++i) { if (edgeMatrix[vertex][i] && coloring[i] == coloring[vertex]) { coloring[i] = -1; @@ -316,7 +317,7 @@ static void uncolorSameNeighbors(std::queue &uncolored, int *coloring, cons } } -static bool tryAddEdge(int *coloring, int * const *edgeMatrix, int vertexCount, int vertexA, int vertexB, int *coloringBuffer) { +static bool tryAddEdge(int *coloring, int *const *edgeMatrix, int vertexCount, int vertexA, int vertexB, int *coloringBuffer) { static const int FIRST_POSSIBLE_COLOR[8] = { -1, 0, 1, 0, 2, 2, 1, 0 }; edgeMatrix[vertexA][vertexB] = 1; edgeMatrix[vertexB][vertexA] = 1; @@ -358,7 +359,7 @@ static bool tryAddEdge(int *coloring, int * const *edgeMatrix, int vertexCount, } static int cmpDoublePtr(const void *a, const void *b) { - return sign(**reinterpret_cast(a)-**reinterpret_cast(b)); + return sign(**reinterpret_cast(a)-**reinterpret_cast(b)); } void edgeColoringByDistance(Shape &shape, double angleThreshold, unsigned long long seed) { diff --git a/thirdparty/msdfgen/core/edge-segments.cpp b/thirdparty/msdfgen/core/edge-segments.cpp index 5274a9a5a15b..4fef89b95bc9 100644 --- a/thirdparty/msdfgen/core/edge-segments.cpp +++ b/thirdparty/msdfgen/core/edge-segments.cpp @@ -56,18 +56,42 @@ CubicSegment::CubicSegment(Point2 p0, Point2 p1, Point2 p2, Point2 p3, EdgeColor p[3] = p3; } -LinearSegment * LinearSegment::clone() const { +LinearSegment *LinearSegment::clone() const { return new LinearSegment(p[0], p[1], color); } -QuadraticSegment * QuadraticSegment::clone() const { +QuadraticSegment *QuadraticSegment::clone() const { return new QuadraticSegment(p[0], p[1], p[2], color); } -CubicSegment * CubicSegment::clone() const { +CubicSegment *CubicSegment::clone() const { return new CubicSegment(p[0], p[1], p[2], p[3], color); } +int LinearSegment::type() const { + return (int) EDGE_TYPE; +} + +int QuadraticSegment::type() const { + return (int) EDGE_TYPE; +} + +int CubicSegment::type() const { + return (int) EDGE_TYPE; +} + +const Point2 *LinearSegment::controlPoints() const { + return p; +} + +const Point2 *QuadraticSegment::controlPoints() const { + return p; +} + +const Point2 *CubicSegment::controlPoints() const { + return p; +} + Point2 LinearSegment::point(double param) const { return mix(p[0], p[1], param); } @@ -483,7 +507,7 @@ void CubicSegment::splitInThirds(EdgeSegment *&part1, EdgeSegment *&part2, EdgeS part3 = new CubicSegment(point(2/3.), mix(mix(p[1], p[2], 2/3.), mix(p[2], p[3], 2/3.), 2/3.), p[2] == p[3] ? p[3] : mix(p[2], p[3], 2/3.), p[3], color); } -EdgeSegment * QuadraticSegment::convertToCubic() const { +EdgeSegment *QuadraticSegment::convertToCubic() const { return new CubicSegment(p[0], mix(p[0], p[1], 2/3.), mix(p[1], p[2], 1/3.), p[2], color); } diff --git a/thirdparty/msdfgen/core/edge-segments.h b/thirdparty/msdfgen/core/edge-segments.h index 1c8fb599ff24..71ce8fc4ab65 100644 --- a/thirdparty/msdfgen/core/edge-segments.h +++ b/thirdparty/msdfgen/core/edge-segments.h @@ -1,8 +1,8 @@ #pragma once -#include "Vector2.h" -#include "SignedDistance.h" +#include "Vector2.hpp" +#include "SignedDistance.hpp" #include "EdgeColor.h" namespace msdfgen { @@ -20,7 +20,11 @@ class EdgeSegment { EdgeSegment(EdgeColor edgeColor = WHITE) : color(edgeColor) { } virtual ~EdgeSegment() { } /// Creates a copy of the edge segment. - virtual EdgeSegment * clone() const = 0; + 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. @@ -51,10 +55,16 @@ class EdgeSegment { class LinearSegment : public EdgeSegment { public: + enum EdgeType { + EDGE_TYPE = 1 + }; + Point2 p[2]; LinearSegment(Point2 p0, Point2 p1, EdgeColor edgeColor = WHITE); - LinearSegment * clone() const; + 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; @@ -74,10 +84,16 @@ class LinearSegment : public EdgeSegment { 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; + 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; @@ -91,7 +107,7 @@ class QuadraticSegment : public EdgeSegment { void moveEndPoint(Point2 to); void splitInThirds(EdgeSegment *&part1, EdgeSegment *&part2, EdgeSegment *&part3) const; - EdgeSegment * convertToCubic() const; + EdgeSegment *convertToCubic() const; }; @@ -99,10 +115,16 @@ class QuadraticSegment : public EdgeSegment { 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; + 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; diff --git a/thirdparty/msdfgen/core/edge-selectors.h b/thirdparty/msdfgen/core/edge-selectors.h index 3620999f82ae..6b8e2d943f2b 100644 --- a/thirdparty/msdfgen/core/edge-selectors.h +++ b/thirdparty/msdfgen/core/edge-selectors.h @@ -1,8 +1,8 @@ #pragma once -#include "Vector2.h" -#include "SignedDistance.h" +#include "Vector2.hpp" +#include "SignedDistance.hpp" #include "edge-segments.h" namespace msdfgen { diff --git a/thirdparty/msdfgen/core/equation-solver.cpp b/thirdparty/msdfgen/core/equation-solver.cpp index 4144fa3340ef..7c1cbb39f85f 100644 --- a/thirdparty/msdfgen/core/equation-solver.cpp +++ b/thirdparty/msdfgen/core/equation-solver.cpp @@ -49,7 +49,7 @@ static int solveCubicNormed(double x[3], double a, double b, double c) { x[2] = q*cos(1/3.*(t-2*M_PI))-a; return 3; } else { - double u = (r < 0 ? 1 : -1)*pow(fabs(r)+sqrt(r2-q3), 1/3.); + double u = (r < 0 ? 1 : -1)*pow(fabs(r)+sqrt(r2-q3), 1/3.); double v = u == 0 ? 0 : q/u; x[0] = (u+v)-a; if (u == v || fabs(u-v) < 1e-12*fabs(u+v)) { diff --git a/thirdparty/msdfgen/core/equation-solver.h b/thirdparty/msdfgen/core/equation-solver.h index bae097b2b9a5..bfeeb1582302 100644 --- a/thirdparty/msdfgen/core/equation-solver.h +++ b/thirdparty/msdfgen/core/equation-solver.h @@ -1,6 +1,8 @@ #pragma once +#include "base.h" + namespace msdfgen { // ax^2 + bx + c = 0 diff --git a/thirdparty/msdfgen/core/generator-config.h b/thirdparty/msdfgen/core/generator-config.h index b430d37f3c49..b7b153477f65 100644 --- a/thirdparty/msdfgen/core/generator-config.h +++ b/thirdparty/msdfgen/core/generator-config.h @@ -1,7 +1,6 @@ #pragma once -#include #include "BitmapRef.hpp" #ifndef MSDFGEN_PUBLIC diff --git a/thirdparty/msdfgen/core/msdf-error-correction.h b/thirdparty/msdfgen/core/msdf-error-correction.h index d5384c932975..6318f184bbc6 100644 --- a/thirdparty/msdfgen/core/msdf-error-correction.h +++ b/thirdparty/msdfgen/core/msdf-error-correction.h @@ -1,7 +1,7 @@ #pragma once -#include "Vector2.h" +#include "Vector2.hpp" #include "Projection.h" #include "Shape.h" #include "BitmapRef.hpp" diff --git a/thirdparty/msdfgen/core/pixel-conversion.hpp b/thirdparty/msdfgen/core/pixel-conversion.hpp index 7e9b6d08f0a3..3ef8a2d1da88 100644 --- a/thirdparty/msdfgen/core/pixel-conversion.hpp +++ b/thirdparty/msdfgen/core/pixel-conversion.hpp @@ -5,8 +5,6 @@ namespace msdfgen { -typedef unsigned char byte; - inline byte pixelFloatToByte(float x) { return byte(clamp(256.f*x, 255.f)); } diff --git a/thirdparty/msdfgen/core/rasterization.h b/thirdparty/msdfgen/core/rasterization.h index 82d0c73d95e3..8ba41cd64523 100644 --- a/thirdparty/msdfgen/core/rasterization.h +++ b/thirdparty/msdfgen/core/rasterization.h @@ -1,7 +1,7 @@ #pragma once -#include "Vector2.h" +#include "Vector2.hpp" #include "Shape.h" #include "Projection.h" #include "Scanline.h" diff --git a/thirdparty/msdfgen/core/render-sdf.h b/thirdparty/msdfgen/core/render-sdf.h index 7f2d270b6734..0fa695acf6d9 100644 --- a/thirdparty/msdfgen/core/render-sdf.h +++ b/thirdparty/msdfgen/core/render-sdf.h @@ -1,7 +1,7 @@ #pragma once -#include "Vector2.h" +#include "Vector2.hpp" #include "BitmapRef.hpp" namespace msdfgen { diff --git a/thirdparty/msdfgen/core/sdf-error-estimation.h b/thirdparty/msdfgen/core/sdf-error-estimation.h index d2fd40d2b8e6..f9008222abc8 100644 --- a/thirdparty/msdfgen/core/sdf-error-estimation.h +++ b/thirdparty/msdfgen/core/sdf-error-estimation.h @@ -1,7 +1,7 @@ #pragma once -#include "Vector2.h" +#include "Vector2.hpp" #include "Shape.h" #include "Projection.h" #include "Scanline.h" diff --git a/thirdparty/msdfgen/core/shape-description.cpp b/thirdparty/msdfgen/core/shape-description.cpp index a096fa25410d..32c515d120ed 100644 --- a/thirdparty/msdfgen/core/shape-description.cpp +++ b/thirdparty/msdfgen/core/shape-description.cpp @@ -244,34 +244,37 @@ bool writeShapeDescription(FILE *output, const Shape &shape) { default:; } } - if (const LinearSegment *e = dynamic_cast(&**edge)) { - fprintf(output, "\t"); - writeCoord(output, e->p[0]); - fprintf(output, ";\n"); - if (colorCode) - fprintf(output, "\t\t%c;\n", colorCode); - } - if (const QuadraticSegment *e = dynamic_cast(&**edge)) { - fprintf(output, "\t"); - writeCoord(output, e->p[0]); - fprintf(output, ";\n\t\t"); - if (colorCode) - fprintf(output, "%c", colorCode); - fprintf(output, "("); - writeCoord(output, e->p[1]); - fprintf(output, ");\n"); - } - if (const CubicSegment *e = dynamic_cast(&**edge)) { - fprintf(output, "\t"); - writeCoord(output, e->p[0]); - fprintf(output, ";\n\t\t"); - if (colorCode) - fprintf(output, "%c", colorCode); - fprintf(output, "("); - writeCoord(output, e->p[1]); - fprintf(output, "; "); - writeCoord(output, e->p[2]); - fprintf(output, ");\n"); + const Point2 *p = (*edge)->controlPoints(); + switch ((*edge)->type()) { + case (int) LinearSegment::EDGE_TYPE: + fprintf(output, "\t"); + writeCoord(output, p[0]); + fprintf(output, ";\n"); + if (colorCode) + fprintf(output, "\t\t%c;\n", colorCode); + break; + case (int) QuadraticSegment::EDGE_TYPE: + fprintf(output, "\t"); + writeCoord(output, p[0]); + fprintf(output, ";\n\t\t"); + if (colorCode) + fprintf(output, "%c", colorCode); + fprintf(output, "("); + writeCoord(output, p[1]); + fprintf(output, ");\n"); + break; + case (int) CubicSegment::EDGE_TYPE: + fprintf(output, "\t"); + writeCoord(output, p[0]); + fprintf(output, ";\n\t\t"); + if (colorCode) + fprintf(output, "%c", colorCode); + fprintf(output, "("); + writeCoord(output, p[1]); + fprintf(output, "; "); + writeCoord(output, p[2]); + fprintf(output, ");\n"); + break; } } fprintf(output, "\t#\n"); diff --git a/thirdparty/msdfgen/core/shape-description.h b/thirdparty/msdfgen/core/shape-description.h index 5df7c50a035e..6e2e22367452 100644 --- a/thirdparty/msdfgen/core/shape-description.h +++ b/thirdparty/msdfgen/core/shape-description.h @@ -1,7 +1,6 @@ #pragma once -#include #include #include "Shape.h" diff --git a/thirdparty/msdfgen/msdfgen.h b/thirdparty/msdfgen/msdfgen.h index c9ae4f52dcce..dff8beb6347e 100644 --- a/thirdparty/msdfgen/msdfgen.h +++ b/thirdparty/msdfgen/msdfgen.h @@ -4,7 +4,7 @@ /* * MULTI-CHANNEL SIGNED DISTANCE FIELD GENERATOR * --------------------------------------------- - * A utility by Viktor Chlumsky, (c) 2014 - 2022 + * A utility by Viktor Chlumsky, (c) 2014 - 2023 * * 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, @@ -15,8 +15,9 @@ * */ +#include "core/base.h" #include "core/arithmetics.hpp" -#include "core/Vector2.h" +#include "core/Vector2.hpp" #include "core/Projection.h" #include "core/Scanline.h" #include "core/Shape.h"