From 001f1f868a7622b430ee40abf01ba175a09e285d Mon Sep 17 00:00:00 2001 From: Clifford Yapp <238416+starseeker@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:42:56 -0400 Subject: [PATCH] Updates for compiling with gcc on Linux --- example/src/stb_truetype.hpp | 22 ++++++++++++---------- src/stb_truetype.hpp | 22 ++++++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/example/src/stb_truetype.hpp b/example/src/stb_truetype.hpp index f1be2e3..6adeff8 100644 --- a/example/src/stb_truetype.hpp +++ b/example/src/stb_truetype.hpp @@ -112,11 +112,13 @@ #pragma once +#include #include #include #include #include #include +#include #include #include @@ -1234,8 +1236,8 @@ inline static std::int_fast32_t stbtt__GetGlyphShapeTT(const stbtt_fontinfo& inf } // Find transformation scales. - const float m{ std::sqrtf(mtx[0] * mtx[0] + mtx[1] * mtx[1]) }; - const float n{ std::sqrtf(mtx[2] * mtx[2] + mtx[3] * mtx[3]) }; + const float m{ std::sqrt(mtx[0] * mtx[0] + mtx[1] * mtx[1]) }; + const float n{ std::sqrt(mtx[2] * mtx[2] + mtx[3] * mtx[3]) }; // Get indexed glyph. std::vector comp_verts{}; @@ -1918,10 +1920,10 @@ inline void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo& font, const st else { // move to integral bboxes (treating pixels as little squares, what pixels get touched)? - ix0 = static_cast(std::floorf(x0 * scale_x + shift_x)); - iy0 = static_cast(std::floorf(-y1 * scale_y + shift_y)); - ix1 = static_cast(std::ceilf(x1 * scale_x + shift_x)); - iy1 = static_cast(std::ceilf(-y0 * scale_y + shift_y)); + ix0 = static_cast(std::floor(x0 * scale_x + shift_x)); + iy0 = static_cast(std::floor(-y1 * scale_y + shift_y)); + ix1 = static_cast(std::ceil(x1 * scale_x + shift_x)); + iy1 = static_cast(std::ceil(-y0 * scale_y + shift_y)); } } @@ -2324,7 +2326,7 @@ inline static void stbtt__rasterize_sorted_edges(stbtt__bitmap& result, stbtt__e for (std::int_fast32_t i{}; i < result.w; ++i) { sum += scanline2[i]; - const std::int_fast32_t m{ std::clamp(static_cast(std::round(std::abs(scanline[i] + sum) * 255.0F)), 0, 255) }; + const std::int_fast32_t m{ std::clamp(static_cast(std::round(std::abs(scanline[i] + sum) * 255.0F)), 0, 255) }; result.pixels[j * result.stride + i] = static_cast(m); } } @@ -2573,8 +2575,8 @@ inline static void stbtt__tesselate_cubic(std::vector& points, std const float dy2{ y3 - y2 }; const float dx{ x3 - x0 }; const float dy{ y3 - y0 }; - const float longlen{ std::sqrtf(dx0 * dx0 + dy0 * dy0) + std::sqrtf(dx1 * dx1 + dy1 * dy1) + std::sqrtf(dx2 * dx2 + dy2 * dy2) }; - const float shortlen{ std::sqrtf(dx * dx + dy * dy) }; + const float longlen{ std::sqrt(dx0 * dx0 + dy0 * dy0) + std::sqrt(dx1 * dx1 + dy1 * dy1) + std::sqrt(dx2 * dx2 + dy2 * dy2) }; + const float shortlen{ std::sqrt(dx * dx + dy * dy) }; const float flatness_squared{ longlen * longlen - shortlen * shortlen }; if (flatness_squared > objspace_flatness_squared) @@ -2867,4 +2869,4 @@ AUTHORS 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. ------------------------------------------------------------------------------ -*/ \ No newline at end of file +*/ diff --git a/src/stb_truetype.hpp b/src/stb_truetype.hpp index f1be2e3..6adeff8 100644 --- a/src/stb_truetype.hpp +++ b/src/stb_truetype.hpp @@ -112,11 +112,13 @@ #pragma once +#include #include #include #include #include #include +#include #include #include @@ -1234,8 +1236,8 @@ inline static std::int_fast32_t stbtt__GetGlyphShapeTT(const stbtt_fontinfo& inf } // Find transformation scales. - const float m{ std::sqrtf(mtx[0] * mtx[0] + mtx[1] * mtx[1]) }; - const float n{ std::sqrtf(mtx[2] * mtx[2] + mtx[3] * mtx[3]) }; + const float m{ std::sqrt(mtx[0] * mtx[0] + mtx[1] * mtx[1]) }; + const float n{ std::sqrt(mtx[2] * mtx[2] + mtx[3] * mtx[3]) }; // Get indexed glyph. std::vector comp_verts{}; @@ -1918,10 +1920,10 @@ inline void stbtt_GetGlyphBitmapBoxSubpixel(const stbtt_fontinfo& font, const st else { // move to integral bboxes (treating pixels as little squares, what pixels get touched)? - ix0 = static_cast(std::floorf(x0 * scale_x + shift_x)); - iy0 = static_cast(std::floorf(-y1 * scale_y + shift_y)); - ix1 = static_cast(std::ceilf(x1 * scale_x + shift_x)); - iy1 = static_cast(std::ceilf(-y0 * scale_y + shift_y)); + ix0 = static_cast(std::floor(x0 * scale_x + shift_x)); + iy0 = static_cast(std::floor(-y1 * scale_y + shift_y)); + ix1 = static_cast(std::ceil(x1 * scale_x + shift_x)); + iy1 = static_cast(std::ceil(-y0 * scale_y + shift_y)); } } @@ -2324,7 +2326,7 @@ inline static void stbtt__rasterize_sorted_edges(stbtt__bitmap& result, stbtt__e for (std::int_fast32_t i{}; i < result.w; ++i) { sum += scanline2[i]; - const std::int_fast32_t m{ std::clamp(static_cast(std::round(std::abs(scanline[i] + sum) * 255.0F)), 0, 255) }; + const std::int_fast32_t m{ std::clamp(static_cast(std::round(std::abs(scanline[i] + sum) * 255.0F)), 0, 255) }; result.pixels[j * result.stride + i] = static_cast(m); } } @@ -2573,8 +2575,8 @@ inline static void stbtt__tesselate_cubic(std::vector& points, std const float dy2{ y3 - y2 }; const float dx{ x3 - x0 }; const float dy{ y3 - y0 }; - const float longlen{ std::sqrtf(dx0 * dx0 + dy0 * dy0) + std::sqrtf(dx1 * dx1 + dy1 * dy1) + std::sqrtf(dx2 * dx2 + dy2 * dy2) }; - const float shortlen{ std::sqrtf(dx * dx + dy * dy) }; + const float longlen{ std::sqrt(dx0 * dx0 + dy0 * dy0) + std::sqrt(dx1 * dx1 + dy1 * dy1) + std::sqrt(dx2 * dx2 + dy2 * dy2) }; + const float shortlen{ std::sqrt(dx * dx + dy * dy) }; const float flatness_squared{ longlen * longlen - shortlen * shortlen }; if (flatness_squared > objspace_flatness_squared) @@ -2867,4 +2869,4 @@ AUTHORS 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. ------------------------------------------------------------------------------ -*/ \ No newline at end of file +*/