diff --git a/src/hb-font.cc b/src/hb-font.cc index ec09c0967..817a1a7b0 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -139,13 +139,10 @@ hb_font_get_nominal_glyphs_default (hb_font_t *font, for (unsigned int i = 0; i < count; i++) { if (!font->get_nominal_glyph (*first_unicode, first_glyph)) - return i; + return i; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - first_unicode = (hb_codepoint_t *) &StructAtOffset (first_unicode, unicode_stride); - first_glyph = (hb_codepoint_t *) &StructAtOffset (first_glyph, glyph_stride); -#pragma GCC diagnostic pop + first_unicode = &StructAtOffsetUnaligned (first_unicode, unicode_stride); + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); } return count; } @@ -241,11 +238,8 @@ hb_font_get_glyph_h_advances_default (hb_font_t* font, for (unsigned int i = 0; i < count; i++) { *first_advance = font->get_glyph_h_advance (*first_glyph); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - first_glyph = (hb_codepoint_t *) &StructAtOffset (first_glyph, glyph_stride); - first_advance = (hb_position_t *) &StructAtOffset (first_advance, advance_stride); -#pragma GCC diagnostic pop + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } return; } @@ -256,10 +250,7 @@ hb_font_get_glyph_h_advances_default (hb_font_t* font, for (unsigned int i = 0; i < count; i++) { *first_advance = font->parent_scale_x_distance (*first_advance); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - first_advance = (hb_position_t *) &StructAtOffset (first_advance, advance_stride); -#pragma GCC diagnostic pop + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } } @@ -279,11 +270,8 @@ hb_font_get_glyph_v_advances_default (hb_font_t* font, for (unsigned int i = 0; i < count; i++) { *first_advance = font->get_glyph_v_advance (*first_glyph); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - first_glyph = (hb_codepoint_t *) &StructAtOffset (first_glyph, glyph_stride); - first_advance = (hb_position_t *) &StructAtOffset (first_advance, advance_stride); -#pragma GCC diagnostic pop + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } return; } @@ -294,10 +282,7 @@ hb_font_get_glyph_v_advances_default (hb_font_t* font, for (unsigned int i = 0; i < count; i++) { *first_advance = font->parent_scale_y_distance (*first_advance); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - first_advance = (hb_position_t *) &StructAtOffset (first_advance, advance_stride); -#pragma GCC diagnostic pop + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } } diff --git a/src/hb-ft.cc b/src/hb-ft.cc index 653d4374f..1900f30bc 100644 --- a/src/hb-ft.cc +++ b/src/hb-ft.cc @@ -228,11 +228,8 @@ hb_ft_get_nominal_glyphs (hb_font_t *font HB_UNUSED, done < count && (*first_glyph = FT_Get_Char_Index (ft_font->ft_face, *first_unicode)); done++) { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - first_unicode = (hb_codepoint_t *) &StructAtOffset (first_unicode, unicode_stride); - first_glyph = (hb_codepoint_t *) &StructAtOffset (first_glyph, glyph_stride); -#pragma GCC diagnostic pop + first_unicode = &StructAtOffsetUnaligned (first_unicode, unicode_stride); + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); } /* We don't need to do ft_font->symbol dance here, since HB calls the singular * nominal_glyph() for what we don't handle here. */ @@ -295,11 +292,8 @@ hb_ft_get_glyph_h_advances (hb_font_t* font, void* font_data, } *first_advance = (v * mult + (1<<9)) >> 10; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - first_glyph = (hb_codepoint_t *) &StructAtOffset (first_glyph, glyph_stride); - first_advance = (hb_position_t *) &StructAtOffset (first_advance, advance_stride); -#pragma GCC diagnostic pop + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } } diff --git a/src/hb-machinery.hh b/src/hb-machinery.hh index f09c24564..ccad561b7 100644 --- a/src/hb-machinery.hh +++ b/src/hb-machinery.hh @@ -64,6 +64,22 @@ static inline const Type& StructAtOffset(const void *P, unsigned int offset) template static inline Type& StructAtOffset(void *P, unsigned int offset) { return * reinterpret_cast ((char *) P + offset); } +template +static inline const Type& StructAtOffsetUnaligned(const void *P, unsigned int offset) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-align" + return * reinterpret_cast ((char *) P + offset); +#pragma GCC diagnostic pop +} +template +static inline Type& StructAtOffsetUnaligned(void *P, unsigned int offset) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-align" + return * reinterpret_cast ((char *) P + offset); +#pragma GCC diagnostic pop +} /* StructAfter(X) returns the struct T& that is placed after X. * Works with X of variable size also. X must implement get_size() */ diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 42080210b..0526c35cb 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -1054,11 +1054,8 @@ struct cmap done < count && get_glyph_funcZ (get_glyph_data, *first_unicode, first_glyph); done++) { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - first_unicode = (hb_codepoint_t *) &StructAtOffset (first_unicode, unicode_stride); - first_glyph = (hb_codepoint_t *) &StructAtOffset (first_glyph, glyph_stride); -#pragma GCC diagnostic pop + first_unicode = &StructAtOffsetUnaligned (first_unicode, unicode_stride); + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); } return done; } diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index 7084d557b..20b09df52 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -112,11 +112,8 @@ hb_ot_get_glyph_h_advances (hb_font_t* font, void* font_data, for (unsigned int i = 0; i < count; i++) { *first_advance = font->em_scale_x (hmtx.get_advance (*first_glyph, font)); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - first_glyph = (hb_codepoint_t *) &StructAtOffset (first_glyph, glyph_stride); - first_advance = (hb_position_t *) &StructAtOffset (first_advance, advance_stride); -#pragma GCC diagnostic pop + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } } @@ -135,11 +132,8 @@ hb_ot_get_glyph_v_advances (hb_font_t* font, void* font_data, for (unsigned int i = 0; i < count; i++) { *first_advance = font->em_scale_y (-(int) vmtx.get_advance (*first_glyph, font)); -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" - first_glyph = (hb_codepoint_t *) &StructAtOffset (first_glyph, glyph_stride); - first_advance = (hb_position_t *) &StructAtOffset (first_advance, advance_stride); -#pragma GCC diagnostic pop + first_glyph = &StructAtOffsetUnaligned (first_glyph, glyph_stride); + first_advance = &StructAtOffsetUnaligned (first_advance, advance_stride); } }