Merge branch 'ming-warnings' into 'master'

Fix some MinGW warnings

See merge request cairo/cairo!247
This commit is contained in:
Adrian Johnson 2021-09-02 20:36:19 +00:00
commit 918fe02666
11 changed files with 72 additions and 239 deletions

View file

@ -74,8 +74,13 @@
#endif
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
#define CAIRO_BOILERPLATE_PRINTF_FORMAT(fmt_index, va_index) \
#ifdef __MINGW32__
#define CAIRO_BOILERPLATE_PRINTF_FORMAT(fmt_index, va_index) \
__attribute__((__format__(__MINGW_PRINTF_FORMAT, fmt_index, va_index)))
#else
#define CAIRO_BOILERPLATE_PRINTF_FORMAT(fmt_index, va_index) \
__attribute__((__format__(__printf__, fmt_index, va_index)))
#endif
#else
#define CAIRO_BOILERPLATE_PRINTF_FORMAT(fmt_index, va_index)
#endif

View file

@ -107,8 +107,13 @@
#endif
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
#ifdef __MINGW32__
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
__attribute__((__format__(__MINGW_PRINTF_FORMAT, fmt_index, va_index)))
#else
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
__attribute__((__format__(__printf__, fmt_index, va_index)))
#endif
#else
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index)
#endif

View file

@ -93,6 +93,11 @@
#define FT_LCD_FILTER_LEGACY 16
#endif
/* FreeType version older than 2.11 does not have the FT_RENDER_MODE_SDF enum value in FT_Render_Mode */
#if FREETYPE_MAJOR > 2 || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR >= 11)
#define HAVE_FT_RENDER_MODE_SDF 1
#endif
#define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0)
#define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0))
#define DOUBLE_FROM_16_16(t) ((double)(t) / 65536.0)
@ -1498,6 +1503,9 @@ _render_glyph_outline (FT_Face face,
case FT_RENDER_MODE_LIGHT:
case FT_RENDER_MODE_NORMAL:
case FT_RENDER_MODE_MAX:
#if HAVE_FT_RENDER_MODE_SDF
case FT_RENDER_MODE_SDF:
#endif
default:
format = CAIRO_FORMAT_A8;
break;
@ -1531,6 +1539,9 @@ _render_glyph_outline (FT_Face face,
case FT_RENDER_MODE_LIGHT:
case FT_RENDER_MODE_NORMAL:
case FT_RENDER_MODE_MAX:
#if HAVE_FT_RENDER_MODE_SDF
case FT_RENDER_MODE_SDF:
#endif
default:
break;
}
@ -3241,8 +3252,6 @@ _cairo_ft_font_face_get_implementation (void *abstract_face,
const cairo_matrix_t *ctm,
const cairo_font_options_t *options)
{
cairo_ft_font_face_t *font_face = abstract_face;
/* The handling of font options is different depending on how the
* font face was created. When the user creates a font face with
* cairo_ft_font_face_create_for_ft_face(), then the load flags
@ -3254,6 +3263,8 @@ _cairo_ft_font_face_get_implementation (void *abstract_face,
*/
#if CAIRO_HAS_FC_FONT
cairo_ft_font_face_t *font_face = abstract_face;
/* If we have an unresolved pattern, resolve it and create
* unscaled font. Otherwise, use the ones stored in font_face.
*/

View file

@ -629,7 +629,7 @@ _hash_mix_bits (uint64_t hash)
static uintptr_t
_cairo_scaled_font_compute_hash (cairo_scaled_font_t *scaled_font)
{
uintptr_t hash = FNV1_64_INIT;
uint64_t hash = FNV1_64_INIT;
/* We do a bytewise hash on the font matrices */
hash = _hash_matrix_fnv (&scaled_font->font_matrix, hash);

View file

@ -987,11 +987,18 @@ cairo_win32_surface_create_with_format (HDC hdc, cairo_format_t format)
cairo_device_t *device;
switch (format) {
default:
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
case CAIRO_FORMAT_ARGB32:
case CAIRO_FORMAT_RGB24:
break;
case CAIRO_FORMAT_INVALID:
case CAIRO_FORMAT_A8:
case CAIRO_FORMAT_A1:
case CAIRO_FORMAT_RGB16_565:
case CAIRO_FORMAT_RGB30:
case CAIRO_FORMAT_RGB96F:
case CAIRO_FORMAT_RGBA128F:
default:
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
case CAIRO_FORMAT_ARGB32:
case CAIRO_FORMAT_RGB24:
break;
}
surface = _cairo_malloc (sizeof (*surface));
@ -1102,14 +1109,19 @@ cairo_win32_surface_create_with_ddb (HDC hdc,
HBITMAP saved_dc_bitmap;
switch (format) {
default:
/* XXX handle these eventually */
case CAIRO_FORMAT_A8:
case CAIRO_FORMAT_A1:
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
case CAIRO_FORMAT_ARGB32:
case CAIRO_FORMAT_RGB24:
break;
case CAIRO_FORMAT_INVALID:
case CAIRO_FORMAT_A8:
case CAIRO_FORMAT_A1:
case CAIRO_FORMAT_RGB16_565:
case CAIRO_FORMAT_RGB30:
case CAIRO_FORMAT_RGB96F:
case CAIRO_FORMAT_RGBA128F:
default:
return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_FORMAT));
case CAIRO_FORMAT_ARGB32:
case CAIRO_FORMAT_RGB24:
break;
}
if (!hdc) {

View file

@ -650,226 +650,6 @@ _cairo_win32_scaled_font_fini (void *abstract_font)
DeleteObject (scaled_font->unscaled_hfont);
}
static cairo_int_status_t
_cairo_win32_scaled_font_type1_text_to_glyphs (cairo_win32_scaled_font_t *scaled_font,
double x,
double y,
const char *utf8,
cairo_glyph_t **glyphs,
int *num_glyphs)
{
uint16_t *utf16;
int n16;
int i;
WORD *glyph_indices = NULL;
cairo_status_t status;
double x_pos, y_pos;
HDC hdc = NULL;
cairo_matrix_t mat;
status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &n16);
if (status)
return status;
glyph_indices = _cairo_malloc_ab (n16 + 1, sizeof (WORD));
if (!glyph_indices) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto FAIL1;
}
hdc = _get_global_font_dc ();
assert (hdc != NULL);
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
if (status)
goto FAIL2;
if (GetGlyphIndicesW (hdc, utf16, n16, glyph_indices, 0) == GDI_ERROR) {
status = _cairo_win32_print_gdi_error ("_cairo_win32_scaled_font_type1_text_to_glyphs:GetGlyphIndicesW");
goto FAIL3;
}
*num_glyphs = n16;
*glyphs = _cairo_malloc_ab (n16, sizeof (cairo_glyph_t));
if (!*glyphs) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto FAIL3;
}
x_pos = x;
y_pos = y;
mat = scaled_font->base.ctm;
status = cairo_matrix_invert (&mat);
assert (status == CAIRO_STATUS_SUCCESS);
_cairo_scaled_font_freeze_cache (&scaled_font->base);
for (i = 0; i < n16; i++) {
cairo_scaled_glyph_t *scaled_glyph;
(*glyphs)[i].index = glyph_indices[i];
(*glyphs)[i].x = x_pos;
(*glyphs)[i].y = y_pos;
status = _cairo_scaled_glyph_lookup (&scaled_font->base,
glyph_indices[i],
CAIRO_SCALED_GLYPH_INFO_METRICS,
&scaled_glyph);
if (status) {
free (*glyphs);
*glyphs = NULL;
break;
}
x = scaled_glyph->x_advance;
y = scaled_glyph->y_advance;
cairo_matrix_transform_distance (&mat, &x, &y);
x_pos += x;
y_pos += y;
}
_cairo_scaled_font_thaw_cache (&scaled_font->base);
FAIL3:
cairo_win32_scaled_font_done_font (&scaled_font->base);
FAIL2:
free (glyph_indices);
FAIL1:
free (utf16);
return status;
}
static cairo_int_status_t
_cairo_win32_scaled_font_text_to_glyphs (void *abstract_font,
double x,
double y,
const char *utf8,
cairo_glyph_t **glyphs,
int *num_glyphs)
{
cairo_win32_scaled_font_t *scaled_font = abstract_font;
uint16_t *utf16;
int n16;
GCP_RESULTSW gcp_results;
unsigned int buffer_size, i;
WCHAR *glyph_indices = NULL;
int *dx = NULL;
cairo_status_t status;
double x_pos, y_pos;
double x_incr, y_incr;
HDC hdc = NULL;
/* GetCharacterPlacement() returns utf16 instead of glyph indices
* for Type 1 fonts. Use GetGlyphIndices for Type 1 fonts. */
if (scaled_font->is_type1)
return _cairo_win32_scaled_font_type1_text_to_glyphs (scaled_font,
x,
y,
utf8,
glyphs,
num_glyphs);
/* Compute a vector in user space along the baseline of length one logical space unit */
x_incr = 1;
y_incr = 0;
cairo_matrix_transform_distance (&scaled_font->base.font_matrix, &x_incr, &y_incr);
x_incr /= scaled_font->logical_scale;
y_incr /= scaled_font->logical_scale;
status = _cairo_utf8_to_utf16 (utf8, -1, &utf16, &n16);
if (status)
return status;
gcp_results.lStructSize = sizeof (GCP_RESULTS);
gcp_results.lpOutString = NULL;
gcp_results.lpOrder = NULL;
gcp_results.lpCaretPos = NULL;
gcp_results.lpClass = NULL;
buffer_size = MAX (n16 * 1.2, 16); /* Initially guess number of chars plus a few */
if (buffer_size > INT_MAX) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto FAIL1;
}
hdc = _get_global_font_dc ();
assert (hdc != NULL);
status = cairo_win32_scaled_font_select_font (&scaled_font->base, hdc);
if (status)
goto FAIL1;
while (TRUE) {
free (glyph_indices);
glyph_indices = NULL;
free (dx);
dx = NULL;
glyph_indices = _cairo_malloc_ab (buffer_size, sizeof (WCHAR));
dx = _cairo_malloc_ab (buffer_size, sizeof (int));
if (!glyph_indices || !dx) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto FAIL2;
}
gcp_results.nGlyphs = buffer_size;
gcp_results.lpDx = dx;
gcp_results.lpGlyphs = glyph_indices;
if (!GetCharacterPlacementW (hdc, utf16, n16,
0,
&gcp_results,
GCP_DIACRITIC | GCP_LIGATE | GCP_GLYPHSHAPE | GCP_REORDER)) {
status = _cairo_win32_print_gdi_error ("_cairo_win32_scaled_font_text_to_glyphs");
goto FAIL2;
}
if (gcp_results.lpDx && gcp_results.lpGlyphs)
break;
/* Too small a buffer, try again */
buffer_size += buffer_size / 2;
if (buffer_size > INT_MAX) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto FAIL2;
}
}
*num_glyphs = gcp_results.nGlyphs;
*glyphs = _cairo_malloc_ab (gcp_results.nGlyphs, sizeof (cairo_glyph_t));
if (!*glyphs) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto FAIL2;
}
x_pos = x;
y_pos = y;
for (i = 0; i < gcp_results.nGlyphs; i++) {
(*glyphs)[i].index = glyph_indices[i];
(*glyphs)[i].x = x_pos ;
(*glyphs)[i].y = y_pos;
x_pos += x_incr * dx[i];
y_pos += y_incr * dx[i];
}
FAIL2:
free (glyph_indices);
free (dx);
cairo_win32_scaled_font_done_font (&scaled_font->base);
FAIL1:
free (utf16);
return status;
}
static unsigned long
_cairo_win32_scaled_font_ucs4_to_index (void *abstract_font,
uint32_t ucs4)
@ -1843,7 +1623,7 @@ const cairo_scaled_font_backend_t _cairo_win32_scaled_font_backend = {
CAIRO_FONT_TYPE_WIN32,
_cairo_win32_scaled_font_fini,
_cairo_win32_scaled_font_glyph_init,
NULL, /* _cairo_win32_scaled_font_text_to_glyphs, FIXME */
NULL, /* _cairo_win32_scaled_font_text_to_glyphs */
_cairo_win32_scaled_font_ucs4_to_index,
_cairo_win32_scaled_font_load_truetype_table,
_cairo_win32_scaled_font_index_to_ucs4,

View file

@ -167,8 +167,15 @@ _cairo_win32_printing_surface_init_language_pack (cairo_win32_printing_surface_t
module = GetModuleHandleW (L"GDI32.DLL");
if (module) {
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-function-type"
#endif
gdi_init_lang_pack = (gdi_init_lang_pack_func_t)
GetProcAddress (module, "GdiInitializeLanguagePack");
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
if (gdi_init_lang_pack)
gdi_init_lang_pack (0);
}

View file

@ -1508,9 +1508,13 @@ _cairo_test_context_run_for_target (cairo_test_context_t *ctx,
if (! RUNNING_ON_VALGRIND) {
void (* volatile old_segfault_handler)(int);
void (* volatile old_segfpe_handler)(int);
#ifdef SIGPIPE
void (* volatile old_sigpipe_handler)(int);
#endif
void (* volatile old_sigabrt_handler)(int);
#ifdef SIGALRM
void (* volatile old_sigalrm_handler)(int);
#endif
/* Set up a checkpoint to get back to in case of segfaults. */
#ifdef SIGSEGV

View file

@ -465,7 +465,9 @@ check_created_pdf(cairo_test_context_t *ctx, const char* filename)
cairo_test_status_t result = CAIRO_TEST_SUCCESS;
int fd;
struct stat st;
#ifdef HAVE_MMAP
void *contents;
#endif
fd = open(filename, O_RDONLY, 0);
if (fd < 0) {

View file

@ -41,7 +41,9 @@
#include <stdlib.h>
#include <string.h>
#if defined(CAIRO_HAS_XLIB_SURFACE) || defined(CAIRO_HAS_XLIB_XRENDER_SURFACE)
static const cairo_user_data_key_t _key;
#endif
#define SINGLE_SURFACE 1

View file

@ -99,8 +99,13 @@
#define CAIRO_BITSWAP8(c) ((((c) * 0x0802LU & 0x22110LU) | ((c) * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16)
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
#ifdef __MINGW32__
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
__attribute__((__format__(__MINGW_PRINTF_FORMAT, fmt_index, va_index)))
#else
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index) \
__attribute__((__format__(__printf__, fmt_index, va_index)))
#endif
#else
#define CAIRO_PRINTF_FORMAT(fmt_index, va_index)
#endif