[HarfBuzz] harfbuzz: Branch 'master' - 6 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Tue Nov 17 18:42:24 PST 2015


 src/hb-buffer-private.hh           |    6 +++---
 src/hb-ot-layout-common-private.hh |    2 +-
 src/hb-ot-layout-private.hh        |    4 ++--
 src/hb-ot-map-private.hh           |    2 +-
 src/hb-ot-shape-complex-arabic.cc  |    3 ++-
 src/hb-private.hh                  |   13 ++++++++++++-
 util/ansi-print.cc                 |   16 +++++++++-------
 util/helper-cairo.cc               |   20 ++++++++++----------
 util/options.cc                    |    2 +-
 util/options.hh                    |   17 +++++++++++++++++
 10 files changed, 58 insertions(+), 27 deletions(-)

New commits:
commit e0082ae60dbd87d433f3b2b9d2bfa64b9a4c3663
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Nov 17 18:42:13 2015 -0800

    Move things around

diff --git a/src/hb-private.hh b/src/hb-private.hh
index 32f8d5e..b735c0d 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -119,15 +119,6 @@ extern "C" void  hb_free_impl(void *ptr);
 #define HB_FUNC __func__
 #endif
 
-/* Use templates for bitwise ops on enums or MSVC's DEFINE_ENUM_FLAG_OPERATORS */
-#ifdef _MSC_VER
-# pragma warning(disable:4200)
-# pragma warning(disable:4800)
-# define HB_MARK_AS_FLAG_T(flags_t)	DEFINE_ENUM_FLAG_OPERATORS (##flags_t##);
-#else
-# define HB_MARK_AS_FLAG_T(flags_t)	template <> class hb_mark_as_flags_t<flags_t> {};
-#endif
-
 /*
  * Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411
  * HB_FALLTHROUGH is an annotation to suppress compiler warnings about switch
@@ -903,8 +894,17 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3)
 /* Enable bitwise ops on enums marked as flags_t */
 /* To my surprise, looks like the function resolver is happy to silently cast
  * one enum to another...  So this doesn't provide the type-checking that I
- * originally had in mind... :( */
-#ifndef _MSC_VER
+ * originally had in mind... :(.
+ *
+ * On MSVC use DEFINE_ENUM_FLAG_OPERATORS.  See:
+ * https://github.com/behdad/harfbuzz/pull/163
+ */
+#ifdef _MSC_VER
+# pragma warning(disable:4200)
+# pragma warning(disable:4800)
+# define HB_MARK_AS_FLAG_T(flags_t)	DEFINE_ENUM_FLAG_OPERATORS (##flags_t##);
+#else
+# define HB_MARK_AS_FLAG_T(flags_t)	template <> class hb_mark_as_flags_t<flags_t> {};
 template <class T> class hb_mark_as_flags_t;
 template <class T> static inline T operator | (T l, T r)
 { hb_mark_as_flags_t<T> unused HB_UNUSED; return T ((unsigned int) l | (unsigned int) r); }
commit dde8cc87bd880bd35baf764820f4c85bd0a58696
Merge: e97835a 167c327
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Nov 17 18:40:10 2015 -0800

    Merge pull request #163 from fanc999/msvc.src
    
    Update the sources so they will compile under Visual Studio

commit 167c3271778cd1a8c4433b9d2230901ce17c099e
Author: Chun-wei Fan <fanchunwei at src.gnome.org>
Date:   Mon Nov 9 17:17:56 2015 +0800

    Fix build on MSVC >= 2012
    
    Use the DEFINE_ENUM_FLAG_OPERATORS macro in winnt.h on Visual Studio,
    which defines the bitwise operators for the enumerations that we want to
    mark as hb_mark_as_flags_t, which will take care of the situation on newer
    Visual Studio (>= 2012), where the build breaks with C2057 errors as the
    underlying types of the enumerations is not clear to the compiler when we
    do a bitwise op within the declaration of the enumerations themselves.
    
    Also disable the C4200 (nonstandard extension used : zero-sized array in
    struct/union) and C4800 ('type' : forcing value to bool 'true' or 'false'
    (performance warning)) warnings as the C4200 is the intended scenario and
    C4800 is harmless but is so far an unavoidable side effect of using
    DEFINE_ENUM_FLAG_OPERATORS.

diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh
index 67c431d..ceccecd 100644
--- a/src/hb-buffer-private.hh
+++ b/src/hb-buffer-private.hh
@@ -48,8 +48,8 @@
 ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20);
 ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t));
 
-template <> class hb_mark_as_flags_t<hb_buffer_flags_t> {};
-template <> class hb_mark_as_flags_t<hb_buffer_serialize_flags_t> {};
+HB_MARK_AS_FLAG_T (hb_buffer_flags_t);
+HB_MARK_AS_FLAG_T (hb_buffer_serialize_flags_t);
 
 enum hb_buffer_scratch_flags_t {
   HB_BUFFER_SCRATCH_FLAG_DEFAULT			= 0x00000000u,
@@ -64,7 +64,7 @@ enum hb_buffer_scratch_flags_t {
   HB_BUFFER_SCRATCH_FLAG_COMPLEX2			= 0x04000000u,
   HB_BUFFER_SCRATCH_FLAG_COMPLEX3			= 0x08000000u,
 };
-template <> class hb_mark_as_flags_t<hb_buffer_scratch_flags_t> {};
+HB_MARK_AS_FLAG_T (hb_buffer_scratch_flags_t);
 
 
 /*
diff --git a/src/hb-ot-layout-common-private.hh b/src/hb-ot-layout-common-private.hh
index 04958a8..5b21f14 100644
--- a/src/hb-ot-layout-common-private.hh
+++ b/src/hb-ot-layout-common-private.hh
@@ -581,7 +581,7 @@ struct LookupFlag : USHORT
 
 } /* namespace OT */
 /* This has to be outside the namespace. */
-template <> class hb_mark_as_flags_t<OT::LookupFlag::Flags> {};
+HB_MARK_AS_FLAG_T (OT::LookupFlag::Flags);
 namespace OT {
 
 struct Lookup
diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh
index 049b232..45897ed 100644
--- a/src/hb-ot-layout-private.hh
+++ b/src/hb-ot-layout-private.hh
@@ -65,7 +65,7 @@ enum hb_ot_layout_glyph_props_flags_t
 					  HB_OT_LAYOUT_GLYPH_PROPS_LIGATED |
 					  HB_OT_LAYOUT_GLYPH_PROPS_MULTIPLIED
 };
-template <> class hb_mark_as_flags_t<hb_ot_layout_glyph_props_flags_t> {};
+HB_MARK_AS_FLAG_T (hb_ot_layout_glyph_props_flags_t);
 
 
 /*
@@ -237,7 +237,7 @@ enum hb_unicode_props_flags_t {
   UPROPS_MASK_IGNORABLE = 0x80u,
   UPROPS_MASK_GEN_CAT   = 0x1Fu
 };
-template <> class hb_mark_as_flags_t<hb_unicode_props_flags_t> {};
+HB_MARK_AS_FLAG_T (hb_unicode_props_flags_t);
 
 static inline void
 _hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_buffer_t *buffer)
diff --git a/src/hb-ot-map-private.hh b/src/hb-ot-map-private.hh
index 1e3ff67..6f62c77 100644
--- a/src/hb-ot-map-private.hh
+++ b/src/hb-ot-map-private.hh
@@ -159,7 +159,7 @@ enum hb_ot_map_feature_flags_t {
   F_MANUAL_ZWJ		= 0x0004u, /* Don't skip over ZWJ when matching. */
   F_GLOBAL_SEARCH	= 0x0008u  /* If feature not found in LangSys, look for it in global feature list and pick one. */
 };
-template <> class hb_mark_as_flags_t<hb_ot_map_feature_flags_t> {};
+HB_MARK_AS_FLAG_T (hb_ot_map_feature_flags_t);
 /* Macro version for where const is desired. */
 #define F_COMBINE(l,r) (hb_ot_map_feature_flags_t ((unsigned int) (l) | (unsigned int) (r)))
 
diff --git a/src/hb-private.hh b/src/hb-private.hh
index 5ed7ff3..32f8d5e 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -119,6 +119,15 @@ extern "C" void  hb_free_impl(void *ptr);
 #define HB_FUNC __func__
 #endif
 
+/* Use templates for bitwise ops on enums or MSVC's DEFINE_ENUM_FLAG_OPERATORS */
+#ifdef _MSC_VER
+# pragma warning(disable:4200)
+# pragma warning(disable:4800)
+# define HB_MARK_AS_FLAG_T(flags_t)	DEFINE_ENUM_FLAG_OPERATORS (##flags_t##);
+#else
+# define HB_MARK_AS_FLAG_T(flags_t)	template <> class hb_mark_as_flags_t<flags_t> {};
+#endif
+
 /*
  * Borrowed from https://bugzilla.mozilla.org/show_bug.cgi?id=1215411
  * HB_FALLTHROUGH is an annotation to suppress compiler warnings about switch
@@ -895,6 +904,7 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3)
 /* To my surprise, looks like the function resolver is happy to silently cast
  * one enum to another...  So this doesn't provide the type-checking that I
  * originally had in mind... :( */
+#ifndef _MSC_VER
 template <class T> class hb_mark_as_flags_t;
 template <class T> static inline T operator | (T l, T r)
 { hb_mark_as_flags_t<T> unused HB_UNUSED; return T ((unsigned int) l | (unsigned int) r); }
@@ -906,6 +916,7 @@ template <class T> static inline T& operator |= (T &l, T r)
 { hb_mark_as_flags_t<T> unused HB_UNUSED; l = l | r; return l; }
 template <class T> static inline T& operator &= (T& l, T r)
 { hb_mark_as_flags_t<T> unused HB_UNUSED; l = l & r; return l; }
+#endif
 
 
 /* Useful for set-operations on small enums.
commit 4d27bb87468a1b84387e7ce084e3d92c0fc8f065
Author: Chun-wei Fan <fanchunwei at src.gnome.org>
Date:   Fri Nov 6 14:28:30 2015 +0800

    hb-ot-shape-complex-arabic.cc: Fix build on Visual Studio
    
    Visual Studio does not like declaring a enum variable within a for
    statement, so fix the build by declaring the enum before doing the for
    loop.

diff --git a/src/hb-ot-shape-complex-arabic.cc b/src/hb-ot-shape-complex-arabic.cc
index 575ab61..5075477 100644
--- a/src/hb-ot-shape-complex-arabic.cc
+++ b/src/hb-ot-shape-complex-arabic.cc
@@ -469,8 +469,9 @@ apply_stch (const hb_ot_shape_plan_t *plan,
   DEBUG_MSG (ARABIC, NULL, "overlap for stretching is %d", overlap);
   int sign = font->x_scale < 0 ? -1 : +1;
   unsigned int extra_glyphs_needed = 0; // Set during MEASURE, used during CUT
+  typedef enum { MEASURE, CUT } step_t;
 
-  for (enum step_t { MEASURE, CUT } step = MEASURE; step <= CUT; step = (step_t) (step + 1))
+  for (step_t step = MEASURE; step <= CUT; step = (step_t) (step + 1))
   {
     unsigned int count = buffer->len;
     hb_glyph_info_t *info = buffer->info;
commit a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0
Author: Chun-wei Fan <fanchunwei at src.gnome.org>
Date:   Tue Nov 3 18:49:34 2015 +0800

    MSVC builds: Add fallback implementation for pre-2013 MSVC
    
    Pre-2013 MSVC does not have scalbn() and scalbnf(), which are used in the
    utility programs.  Add  fallback implementations for these, which can be
    used when necessary.

diff --git a/util/options.hh b/util/options.hh
index 1ef4131..919e4f8 100644
--- a/util/options.hh
+++ b/util/options.hh
@@ -474,5 +474,22 @@ struct format_options_t : option_group_t
   hb_bool_t show_extents;
 };
 
+/* fallback implementation for scalbn()/scalbnf() for pre-2013 MSVC */
+#if defined (_MSC_VER) && (_MSC_VER < 1800)
+
+#ifndef FLT_RADIX
+#define FLT_RADIX 2
+#endif
+
+__inline long double scalbn (long double x, int exp)
+{
+  return x * (pow ((long double) FLT_RADIX, exp));
+}
+
+__inline float scalbnf (float x, int exp)
+{
+  return x * (pow ((float) FLT_RADIX, exp));
+}
+#endif
 
 #endif
commit 998e8dda938cfef0146f1bfc4e8973a0e12d7d35
Author: Chun-wei Fan <fanchunwei at src.gnome.org>
Date:   Mon Nov 2 16:55:29 2015 +0800

    util: Fix build on Visual Studio
    
    Use the fallback implementation for lround() only on pre-2013 Visual
    Studio, and ensure we are clear about the types of the parameters for
    lround() and scalbnf(), since Visual Studio can be quite picky on
    ambiguous parameter types.  Also, use g_ascii_strcasecmp() rather than
    strcasecmp() as we are already using GLib for this code and we are
    assured that g_ascii_strcasemp() is available.
    
    For scalbnf() on pre-2013 Visaul Studio, a fallback implementation is
    needed, but use another forced-included header for those compilers, which
    will be added later.
    
    Also use (char)27 on Visual Studio builds as '\e' is not a recognized
    escape sequence, which will do the same thing.

diff --git a/util/ansi-print.cc b/util/ansi-print.cc
index e9060af..e0ce7b3 100644
--- a/util/ansi-print.cc
+++ b/util/ansi-print.cc
@@ -41,7 +41,7 @@
 #include <unistd.h> /* for isatty() */
 #endif
 
-#ifdef _MSC_VER
+#if defined (_MSC_VER) && (_MSC_VER < 1800)
 static inline long int
 lround (double x)
 {
@@ -52,6 +52,8 @@ lround (double x)
 }
 #endif
 
+#define ESC_E (char)27
+
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
 
 #define CELL_W 8
@@ -298,7 +300,7 @@ block_best (const biimage_t &bi, bool *inverse)
     }
     if (best_s < score) {
       static const char *lower[7] = {"▁", "▂", "▃", "▄", "▅", "▆", "▇"};
-      unsigned int which = lround (((best_i + 1) * 8) / bi.height);
+      unsigned int which = lround ((double) ((best_i + 1) * 8) / bi.height);
       if (1 <= which && which <= 7) {
 	score = best_s;
 	*inverse = best_inv;
@@ -330,7 +332,7 @@ block_best (const biimage_t &bi, bool *inverse)
     }
     if (best_s < score) {
       static const char *left [7] = {"▏", "▎", "▍", "▌", "▋", "▊", "▉"};
-      unsigned int which = lround (((best_i + 1) * 8) / bi.width);
+      unsigned int which = lround ((double) ((best_i + 1) * 8) / bi.width);
       if (1 <= which && which <= 7) {
 	score = best_s;
 	*inverse = best_inv;
@@ -395,7 +397,7 @@ ansi_print_image_rgb24 (const uint32_t *data,
       bi.set (cell);
       if (bi.unicolor) {
         if (last_bg != bi.bg) {
-	  printf ("\e[%dm", 40 + bi.bg);
+	  printf ("%c[%dm", ESC_E, 40 + bi.bg);
 	  last_bg = bi.bg;
 	}
 	printf (" ");
@@ -405,13 +407,13 @@ ansi_print_image_rgb24 (const uint32_t *data,
         const char *c = block_best (bi, &inverse);
 	if (inverse) {
 	  if (last_bg != bi.fg || last_fg != bi.bg) {
-	    printf ("\e[%d;%dm", 30 + bi.bg, 40 + bi.fg);
+	    printf ("%c[%d;%dm", ESC_E, 30 + bi.bg, 40 + bi.fg);
 	    last_bg = bi.fg;
 	    last_fg = bi.bg;
 	  }
 	} else {
 	  if (last_bg != bi.bg || last_fg != bi.fg) {
-	    printf ("\e[%d;%dm", 40 + bi.bg, 30 + bi.fg);
+	    printf ("%c[%d;%dm", ESC_E, 40 + bi.bg, 30 + bi.fg);
 	    last_bg = bi.bg;
 	    last_fg = bi.fg;
 	  }
@@ -419,7 +421,7 @@ ansi_print_image_rgb24 (const uint32_t *data,
 	printf ("%s", c);
       }
     }
-    printf ("\e[0m\n"); /* Reset */
+    printf ("%c[0m\n", ESC_E); /* Reset */
     last_bg = last_fg = -1;
   }
 }
diff --git a/util/helper-cairo.cc b/util/helper-cairo.cc
index 50e22ab..450e5cf 100644
--- a/util/helper-cairo.cc
+++ b/util/helper-cairo.cc
@@ -341,25 +341,25 @@ helper_cairo_create_context (double w, double h,
   }
   if (0)
     ;
-    else if (0 == strcasecmp (extension, "ansi"))
+    else if (0 == g_ascii_strcasecmp (extension, "ansi"))
       constructor2 = _cairo_ansi_surface_create_for_stream;
   #ifdef CAIRO_HAS_PNG_FUNCTIONS
-    else if (0 == strcasecmp (extension, "png"))
+    else if (0 == g_ascii_strcasecmp (extension, "png"))
       constructor2 = _cairo_png_surface_create_for_stream;
   #endif
   #ifdef CAIRO_HAS_SVG_SURFACE
-    else if (0 == strcasecmp (extension, "svg"))
+    else if (0 == g_ascii_strcasecmp (extension, "svg"))
       constructor = cairo_svg_surface_create_for_stream;
   #endif
   #ifdef CAIRO_HAS_PDF_SURFACE
-    else if (0 == strcasecmp (extension, "pdf"))
+    else if (0 == g_ascii_strcasecmp (extension, "pdf"))
       constructor = cairo_pdf_surface_create_for_stream;
   #endif
   #ifdef CAIRO_HAS_PS_SURFACE
-    else if (0 == strcasecmp (extension, "ps"))
+    else if (0 == g_ascii_strcasecmp (extension, "ps"))
       constructor = cairo_ps_surface_create_for_stream;
    #ifdef HAS_EPS
-    else if (0 == strcasecmp (extension, "eps"))
+    else if (0 == g_ascii_strcasecmp (extension, "eps"))
       constructor = _cairo_eps_surface_create_for_stream;
    #endif
   #endif
@@ -478,16 +478,16 @@ helper_cairo_line_from_buffer (helper_cairo_line_t *l,
   for (i = 0; i < (int) l->num_glyphs; i++)
   {
     l->glyphs[i].index = hb_glyph[i].codepoint;
-    l->glyphs[i].x = scalbn ( hb_position->x_offset + x, scale_bits);
-    l->glyphs[i].y = scalbn (-hb_position->y_offset + y, scale_bits);
+    l->glyphs[i].x = scalbn ((double)  hb_position->x_offset + x, scale_bits);
+    l->glyphs[i].y = scalbn ((double) -hb_position->y_offset + y, scale_bits);
     x +=  hb_position->x_advance;
     y += -hb_position->y_advance;
 
     hb_position++;
   }
   l->glyphs[i].index = -1;
-  l->glyphs[i].x = scalbn (x, scale_bits);
-  l->glyphs[i].y = scalbn (y, scale_bits);
+  l->glyphs[i].x = scalbn ((double) x, scale_bits);
+  l->glyphs[i].y = scalbn ((double) y, scale_bits);
 
   if (l->num_clusters) {
     memset ((void *) l->clusters, 0, l->num_clusters * sizeof (l->clusters[0]));
diff --git a/util/options.cc b/util/options.cc
index ca8f906..882e060 100644
--- a/util/options.cc
+++ b/util/options.cc
@@ -569,7 +569,7 @@ font_options_t::get_font (void) const
   else
   {
     for (unsigned int i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++)
-      if (0 == strcasecmp (font_funcs, supported_font_funcs[i].name))
+      if (0 == g_ascii_strcasecmp (font_funcs, supported_font_funcs[i].name))
       {
 	set_font_funcs = supported_font_funcs[i].func;
 	break;


More information about the HarfBuzz mailing list