From fcc6837a860344be76edf40f3d63e98081bc7d86 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Fri, 4 Mar 2022 21:41:14 +0100 Subject: [PATCH] Fix types --- src/_path.h | 12 ++++-------- src/ft2font.cpp | 4 ++-- src/ft2font_wrapper.cpp | 6 +++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/_path.h b/src/_path.h index f4c8fd036d2c..e0e65287349d 100644 --- a/src/_path.h +++ b/src/_path.h @@ -840,7 +840,7 @@ inline bool segments_intersect(const double &x1, // If den == 0 we have two possibilities: if (isclose(den, 0.0)) { - float t_area = (x2*y3 - x3*y2) - x1*(y3 - y2) + y1*(x3 - x2); + double t_area = (x2*y3 - x3*y2) - x1*(y3 - y2) + y1*(x3 - x2); // 1 - If the area of the triangle made by the 3 first points (2 from the first segment // plus one from the second) is zero, they are collinear if (isclose(t_area, 0.0)) { @@ -852,7 +852,6 @@ inline bool segments_intersect(const double &x1, else { return (fmin(x1, x2) <= fmin(x3, x4) && fmin(x3, x4) <= fmax(x1, x2)) || (fmin(x3, x4) <= fmin(x1, x2) && fmin(x1, x2) <= fmax(x3, x4)); - } } // 2 - If t_area is not zero, the segments are parallel, but not collinear @@ -876,7 +875,6 @@ inline bool segments_intersect(const double &x1, template bool path_intersects_path(PathIterator1 &p1, PathIterator2 &p2) { - typedef PathNanRemover no_nans_t; typedef agg::conv_curve curve_t; @@ -901,7 +899,6 @@ bool path_intersects_path(PathIterator1 &p1, PathIterator2 &p2) } c2.rewind(0); c2.vertex(&x21, &y21); - while (c2.vertex(&x22, &y22) != agg::path_cmd_stop) { // if the segment in path 2 is (almost) 0 length, skip to next vertex @@ -1147,16 +1144,15 @@ bool __convert_to_string(PathIterator &path, double last_x = 0.0; double last_y = 0.0; - int size = 0; unsigned code; while ((code = path.vertex(&x[0], &y[0])) != agg::path_cmd_stop) { if (code == CLOSEPOLY) { buffer += codes[4]; } else if (code < 5) { - size = NUM_VERTICES[code]; + size_t size = NUM_VERTICES[code]; - for (int i = 1; i < size; ++i) { + for (size_t i = 1; i < size; ++i) { unsigned subcode = path.vertex(&x[i], &y[i]); if (subcode != code) { return false; @@ -1176,7 +1172,7 @@ bool __convert_to_string(PathIterator &path, buffer += ' '; } - for (int i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { __add_number(x[i], format_code, precision, buffer); buffer += ' '; __add_number(y[i], format_code, precision, buffer); diff --git a/src/ft2font.cpp b/src/ft2font.cpp index 712a244fe77b..56b4bb9b05b1 100644 --- a/src/ft2font.cpp +++ b/src/ft2font.cpp @@ -551,8 +551,8 @@ void FT2Font::get_bitmap_offset(long *x, long *y) void FT2Font::draw_glyphs_to_bitmap(bool antialiased) { - size_t width = (bbox.xMax - bbox.xMin) / 64 + 2; - size_t height = (bbox.yMax - bbox.yMin) / 64 + 2; + long width = (bbox.xMax - bbox.xMin) / 64 + 2; + long height = (bbox.yMax - bbox.yMin) / 64 + 2; image.resize(width, height); diff --git a/src/ft2font_wrapper.cpp b/src/ft2font_wrapper.cpp index fb84feab6913..be125b78ec08 100644 --- a/src/ft2font_wrapper.cpp +++ b/src/ft2font_wrapper.cpp @@ -291,7 +291,7 @@ static unsigned long read_from_file_callback(FT_Stream stream, return 1; // Non-zero signals error, when count == 0. } } - return n_read; + return PyLong_AsUnsignedLong(PyLong_FromSsize_t(n_read)); } static void close_file_callback(FT_Stream stream) @@ -589,7 +589,7 @@ const char *PyFT2Font_get_num_glyphs__doc__ = static PyObject *PyFT2Font_get_num_glyphs(PyFT2Font *self, PyObject *args) { - return PyLong_FromLong(self->x->get_num_glyphs()); + return PyLong_FromSize_t(self->x->get_num_glyphs()); } const char *PyFT2Font_load_char__doc__ = @@ -1545,7 +1545,7 @@ PyMODINIT_FUNC PyInit_ft2font(void) FT_Int major, minor, patch; char version_string[64]; FT_Library_Version(_ft2Library, &major, &minor, &patch); - sprintf(version_string, "%d.%d.%d", major, minor, patch); + snprintf(version_string, sizeof(version_string), "%d.%d.%d", major, minor, patch); PyObject *m = PyModule_Create(&moduledef); if (!m ||