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

Behdad Esfahbod behdad at kemper.freedesktop.org
Sat Jul 5 16:30:52 PDT 2014


 AUTHORS         |    1 
 util/options.cc |   82 +++++++++++++++++++++++++++++++++++++++++++++++---------
 util/options.hh |   30 ++++++++++++++++++++
 3 files changed, 100 insertions(+), 13 deletions(-)

New commits:
commit 8650def73500204b79c651f58b1be3f94a41973d
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sat Jul 5 15:50:18 2014 -0400

    [util] Add option to set font function implementation to use
    
    Supports ft and ot right now.  hb-view currently not rendering with ot.
    Will fix after some clean up.

diff --git a/util/options.cc b/util/options.cc
index c65888e..738fb7a 100644
--- a/util/options.cc
+++ b/util/options.cc
@@ -28,10 +28,24 @@
 
 #ifdef HAVE_FREETYPE
 #include <hb-ft.h>
-#else
+#endif
+#ifdef HAVE_OT
 #include <hb-ot-font.h>
 #endif
 
+struct supported_font_funcs_t {
+	char name[4];
+	void (*func) (hb_font_t *);
+} supported_font_funcs[] =
+{
+#ifdef HAVE_FREETYPE
+  {"ft",	hb_ft_font_set_funcs},
+#endif
+#ifdef HAVE_OT
+  {"ot",	hb_ot_font_set_funcs},
+#endif
+};
+
 
 void
 fail (hb_bool_t suggest_help, const char *format, ...)
@@ -269,7 +283,7 @@ shape_options_t::add_options (option_parser_t *parser)
 			      G_OPTION_ARG_CALLBACK,	(gpointer) &list_shapers,	"List available shapers and quit",	NULL},
     {"shaper",		0, G_OPTION_FLAG_HIDDEN,
 			      G_OPTION_ARG_CALLBACK,	(gpointer) &parse_shapers,	"Hidden duplicate of --shapers",	NULL},
-    {"shapers",		0, 0, G_OPTION_ARG_CALLBACK,	(gpointer) &parse_shapers,	"Comma-separated list of shapers to try","list"},
+    {"shapers",		0, 0, G_OPTION_ARG_CALLBACK,	(gpointer) &parse_shapers,	"Set comma-separated list of shapers to try","list"},
     {"direction",	0, 0, G_OPTION_ARG_STRING,	&this->direction,		"Set text direction (default: auto)",	"ltr/rtl/ttb/btt"},
     {"language",	0, 0, G_OPTION_ARG_STRING,	&this->language,		"Set text language (default: $LANG)",	"langstr"},
     {"script",		0, 0, G_OPTION_ARG_STRING,	&this->script,			"Set text script (default: auto)",	"ISO-15924 tag"},
@@ -336,10 +350,28 @@ shape_options_t::add_options (option_parser_t *parser)
 void
 font_options_t::add_options (option_parser_t *parser)
 {
+  char *text = NULL;
+
+  {
+    ASSERT_STATIC (ARRAY_LENGTH_CONST (supported_font_funcs) > 0);
+    GString *s = g_string_new (NULL);
+    g_string_printf (s, "Set font functions implementation to use (default: %s)\n\n    Supported font function implementations are: %s",
+		     supported_font_funcs[0].name,
+		     supported_font_funcs[0].name);
+    for (unsigned int i = 1; i < ARRAY_LENGTH (supported_font_funcs); i++)
+    {
+      g_string_append_c (s, '/');
+      g_string_append (s, supported_font_funcs[i].name);
+    }
+    text = g_string_free (s, FALSE);
+    parser->free_later (text);
+  }
+
   GOptionEntry entries[] =
   {
-    {"font-file",	0, 0, G_OPTION_ARG_STRING,	&this->font_file,		"Font file-name",					"filename"},
-    {"face-index",	0, 0, G_OPTION_ARG_INT,		&this->face_index,		"Face index (default: 0)",                              "index"},
+    {"font-file",	0, 0, G_OPTION_ARG_STRING,	&this->font_file,		"Set font file-name",			"filename"},
+    {"face-index",	0, 0, G_OPTION_ARG_INT,		&this->face_index,		"Set face index (default: 0)",		"index"},
+    {"font-funcs",	0, 0, G_OPTION_ARG_STRING,	&this->font_funcs,		text,					"format"},
     {NULL}
   };
   parser->add_group (entries,
@@ -484,11 +516,37 @@ font_options_t::get_font (void) const
   hb_font_set_scale (font, upem, upem);
   hb_face_destroy (face);
 
-#ifdef HAVE_FREETYPE
-  hb_ft_font_set_funcs (font);
-#else
-  hb_ot_font_set_funcs (font);
-#endif
+  void (*set_font_funcs) (hb_font_t *) = NULL;
+  if (!font_funcs)
+  {
+    set_font_funcs = supported_font_funcs[0].func;
+  }
+  else
+  {
+    for (unsigned int i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++)
+      if (0 == strcasecmp (font_funcs, supported_font_funcs[i].name))
+      {
+	set_font_funcs = supported_font_funcs[i].func;
+	break;
+      }
+    if (!set_font_funcs)
+    {
+      GString *s = g_string_new (NULL);
+      for (unsigned int i = 0; i < ARRAY_LENGTH (supported_font_funcs); i++)
+      {
+        if (i)
+	  g_string_append_c (s, '/');
+	g_string_append (s, supported_font_funcs[i].name);
+      }
+      char *p = g_string_free (s, FALSE);
+      fail (false, "Unknown font function implementation `%s'; supported values are: %s; default is %s",
+	    font_funcs,
+	    p,
+	    supported_font_funcs[0].name);
+      //free (p);
+    }
+  }
+  set_font_funcs (font);
 
   return font;
 }
diff --git a/util/options.hh b/util/options.hh
index 4437707..223778d 100644
--- a/util/options.hh
+++ b/util/options.hh
@@ -58,12 +58,31 @@
 # define g_mapped_file_unref g_mapped_file_free
 #endif
 
+
+/* A few macros copied from hb-private.hh. */
+
+#if __GNUC__ >= 4
+#define HB_UNUSED	__attribute__((unused))
+#else
+#define HB_UNUSED
+#endif
+
 #undef MIN
 template <typename Type> static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; }
 
 #undef MAX
 template <typename Type> static inline Type MAX (const Type &a, const Type &b) { return a > b ? a : b; }
 
+#undef  ARRAY_LENGTH
+template <typename Type, unsigned int n>
+static inline unsigned int ARRAY_LENGTH (const Type (&)[n]) { return n; }
+/* A const version, but does not detect erratically being called on pointers. */
+#define ARRAY_LENGTH_CONST(__array) ((signed int) (sizeof (__array) / sizeof (__array[0])))
+
+#define _ASSERT_STATIC1(_line, _cond)	HB_UNUSED typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
+#define _ASSERT_STATIC0(_line, _cond)	_ASSERT_STATIC1 (_line, (_cond))
+#define ASSERT_STATIC(_cond)		_ASSERT_STATIC0 (__LINE__, (_cond))
+
 
 void fail (hb_bool_t suggest_help, const char *format, ...) G_GNUC_NORETURN G_GNUC_PRINTF (2, 3);
 
@@ -257,6 +276,7 @@ struct font_options_t : option_group_t
   font_options_t (option_parser_t *parser) {
     font_file = NULL;
     face_index = 0;
+    font_funcs = NULL;
 
     font = NULL;
 
@@ -272,6 +292,7 @@ struct font_options_t : option_group_t
 
   const char *font_file;
   int face_index;
+  const char *font_funcs;
 
   private:
   mutable hb_font_t *font;
commit 2306ad46dce1c53b0b1bfabdc04d70e3b99eabb7
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 4 18:09:29 2014 -0400

    [util] Fix memory issue

diff --git a/util/options.cc b/util/options.cc
index f872bb4..c65888e 100644
--- a/util/options.cc
+++ b/util/options.cc
@@ -371,15 +371,15 @@ void
 output_options_t::add_options (option_parser_t *parser)
 {
   const char *text;
-  char *text_free = NULL;
 
   if (NULL == supported_formats)
     text = "Set output format";
   else
   {
     char *items = g_strjoinv ("/", const_cast<char **> (supported_formats));
-    text = text_free = g_strdup_printf ("Set output format\n\n    Supported formats are: %s", items);
+    text = g_strdup_printf ("Set output format\n\n    Supported output formats are: %s", items);
     g_free (items);
+    parser->free_later ((char *) text);
   }
 
   GOptionEntry entries[] =
@@ -393,8 +393,6 @@ output_options_t::add_options (option_parser_t *parser)
 		     "Output options:",
 		     "Options controlling the output",
 		     this);
-
-  g_free (text_free);
 }
 
 
diff --git a/util/options.hh b/util/options.hh
index a236a5d..4437707 100644
--- a/util/options.hh
+++ b/util/options.hh
@@ -85,11 +85,14 @@ struct option_parser_t
     memset (this, 0, sizeof (*this));
     usage_str = usage;
     context = g_option_context_new (usage);
+    to_free = g_ptr_array_new ();
 
     add_main_options ();
   }
   ~option_parser_t (void) {
     g_option_context_free (context);
+    g_ptr_array_foreach (to_free, (GFunc) g_free, NULL);
+    g_ptr_array_free (to_free, TRUE);
   }
 
   void add_main_options (void);
@@ -100,6 +103,10 @@ struct option_parser_t
 		  const gchar    *help_description,
 		  option_group_t *option_group);
 
+  void free_later (char *p) {
+    g_ptr_array_add (to_free, p);
+  }
+
   void parse (int *argc, char ***argv);
 
   G_GNUC_NORETURN void usage (void) {
@@ -107,8 +114,10 @@ struct option_parser_t
     exit (1);
   }
 
+  private:
   const char *usage_str;
   GOptionContext *context;
+  GPtrArray *to_free;
 };
 
 
commit 14a4a9d649798d32c31f79b4045a885626dffc7f
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue Jul 1 15:51:54 2014 -0400

    Add Roozbeh to AUTHORS
    
    He's been my shadow for all Indic-related changes in the last
    few months.

diff --git a/AUTHORS b/AUTHORS
index c611d7d..81cdc4c 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -4,5 +4,6 @@ Martin Hosken
 Jonathan Kew
 Lars Knoll
 Werner Lemberg
+Roozbeh Pournader
 Owen Taylor
 David Turner


More information about the HarfBuzz mailing list