From 3ee4ea945674c4b96c9aa6b0367bbf22dc8745d1 Mon Sep 17 00:00:00 2001 From: fanc999 Date: Thu, 20 Dec 2018 11:26:54 +0800 Subject: [PATCH] Fix build on older Visual Studio versions (#1499) * src/hb-cff-interp-dict-common.hh: Use ull for unsigned int64_t The llu suffix does not work for older Visual Studio versions (pre-2013), but ull works for all the compilers that we attempt to support. * test/api: Fix build on pre-C99 compilers Ensure variables are declared at the top of the block. * src/hb-dsalgs.hh: Add specialization for hb_is_signed<> for __int8 Pre-Visual Studio 2010 does not consider __int8 (which is typedef'ed to int8_t) to be equivilant to signed char, so the compiler cannot find the corresponding hb_is_signed<> specialization that is needed. The interesting thing is unsigned __int8 is considered to be equivilant to unsigned char, so as the other types (short, int, long) that we look for here, so only the specialization for __int8 is added here. This will fix builds on Visual Studio 2008 at least. --- src/hb-cff-interp-dict-common.hh | 2 +- src/hb-dsalgs.hh | 9 +++++++++ test/api/test-aat-layout.c | 3 ++- test/api/test-subset-cff1.c | 12 ++++++++---- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/hb-cff-interp-dict-common.hh b/src/hb-cff-interp-dict-common.hh index 91d298cea..8000d76b8 100644 --- a/src/hb-cff-interp-dict-common.hh +++ b/src/hb-cff-interp-dict-common.hh @@ -105,7 +105,7 @@ struct DictOpSet : OpSet bool exp_overflow = false; enum Part { INT_PART=0, FRAC_PART, EXP_PART } part = INT_PART; enum Nibble { DECIMAL=10, EXP_POS, EXP_NEG, RESERVED, NEG, END }; - const uint64_t MAX_FRACT = 0xFFFFFFFFFFFFFllu; /* 1^52-1 */ + const uint64_t MAX_FRACT = 0xFFFFFFFFFFFFFull; /* 1^52-1 */ const uint32_t MAX_EXP = 0x7FFu; /* 1^11-1 */ double value = 0.0; diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh index bc05207bc..e7226d9ba 100644 --- a/src/hb-dsalgs.hh +++ b/src/hb-dsalgs.hh @@ -306,6 +306,15 @@ template <> struct hb_is_signed { enum { value = false }; }; template <> struct hb_is_signed { enum { value = false }; }; template <> struct hb_is_signed { enum { value = false }; }; +/* We need to define hb_is_signed for the typedefs we use on pre-Visual Studio 2010 + * for the int8_t type, since __int8/__int64 is not considered the same as char/long. + * The previous lines will suffice for the other types, though. Note that somehow, + * usigned __int8 is considered equal to unsigned char. + */ +#if defined (_MSC_VER) && (_MSC_VER < 1600) +template <> struct hb_is_signed<__int8> { enum { value = true }; }; +#endif + template static inline bool hb_in_range (T u, T lo, T hi) { diff --git a/test/api/test-aat-layout.c b/test/api/test-aat-layout.c index 4054b1736..1384556a8 100644 --- a/test/api/test-aat-layout.c +++ b/test/api/test-aat-layout.c @@ -105,10 +105,11 @@ static void test_aat_has (void) { hb_face_t *morx = hb_test_open_font_file ("fonts/aat-morx.ttf"); + hb_face_t *trak; g_assert (hb_aat_layout_has_substitution (morx)); hb_face_destroy (morx); - hb_face_t *trak = hb_test_open_font_file ("fonts/aat-trak.ttf"); + trak = hb_test_open_font_file ("fonts/aat-trak.ttf"); g_assert (hb_aat_layout_has_tracking (trak)); hb_face_destroy (trak); } diff --git a/test/api/test-subset-cff1.c b/test/api/test-subset-cff1.c index 30204dd90..3ee270261 100644 --- a/test/api/test-subset-cff1.c +++ b/test/api/test-subset-cff1.c @@ -235,10 +235,11 @@ test_subset_cff1_expert (void) hb_face_t *face_subset = hb_test_open_font_file ("fonts/cff1_expert.2D,F6E9,FB00.otf"); hb_set_t *codepoints = hb_set_create (); + hb_face_t *face_test; hb_set_add (codepoints, 0x2D); hb_set_add (codepoints, 0xF6E9); hb_set_add (codepoints, 0xFB00); - hb_face_t *face_test = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints)); + face_test = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints)); hb_set_destroy (codepoints); hb_subset_test_check (face_subset, face_test, HB_TAG ('C','F','F',' ')); @@ -253,10 +254,11 @@ test_subset_cff1_seac (void) { hb_face_t *face = hb_test_open_font_file ("fonts/cff1_seac.otf"); hb_face_t *face_subset = hb_test_open_font_file ("fonts/cff1_seac.C0.otf"); + hb_face_t *face_test; hb_set_t *codepoints = hb_set_create (); hb_set_add (codepoints, 0xC0); /* Agrave */ - hb_face_t *face_test = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints)); + face_test = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints)); hb_set_destroy (codepoints); hb_subset_test_check (face_subset, face_test, HB_TAG ('C','F','F',' ')); @@ -273,10 +275,12 @@ test_subset_cff1_dotsection (void) hb_face_t *face_subset = hb_test_open_font_file ("fonts/cff1_dotsect.nohints.otf"); hb_set_t *codepoints = hb_set_create (); + hb_subset_input_t *input; + hb_face_t *face_test; hb_set_add (codepoints, 0x69); /* i */ - hb_subset_input_t *input = hb_subset_test_create_input (codepoints); + input = hb_subset_test_create_input (codepoints); hb_subset_input_set_drop_hints (input, true); - hb_face_t *face_test = hb_subset_test_create_subset (face, input); + face_test = hb_subset_test_create_subset (face, input); hb_set_destroy (codepoints); hb_subset_test_check (face_subset, face_test, HB_TAG ('C','F','F',' '));