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

Behdad Esfahbod behdad at kemper.freedesktop.org
Fri Jul 25 09:43:08 PDT 2014


 src/hb-common.h             |    2 
 src/hb-open-type-private.hh |    2 
 src/hb-ot-layout-private.hh |    2 
 src/hb-private.hh           |    2 
 src/hb-shape.cc             |  102 +++++++++++++++++++++++++++++++++-----------
 util/options.cc             |    4 +
 6 files changed, 85 insertions(+), 29 deletions(-)

New commits:
commit fe6788bc570d77d5b3aafc68efd51ca6b80499b1
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 12:40:56 2014 -0400

    Typo

diff --git a/src/hb-common.h b/src/hb-common.h
index 32a62e5..f5141b9 100644
--- a/src/hb-common.h
+++ b/src/hb-common.h
@@ -316,7 +316,7 @@ typedef enum
 hb_script_t
 hb_script_from_iso15924_tag (hb_tag_t tag);
 
-/* suger for tag_from_string() then script_from_iso15924_tag */
+/* sugar for tag_from_string() then script_from_iso15924_tag */
 /* len=-1 means s is NUL-terminated */
 hb_script_t
 hb_script_from_string (const char *s, int len);
commit 0de25d4184d2d92b1a2ebb6fa054275aaae4c316
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 12:35:03 2014 -0400

    [util] Note CSS compatibility in --help-features

diff --git a/util/options.cc b/util/options.cc
index 738fb7a..0adc179 100644
--- a/util/options.cc
+++ b/util/options.cc
@@ -304,7 +304,9 @@ shape_options_t::add_options (option_parser_t *parser)
   const gchar *features_help = "Comma-separated list of font features\n"
     "\n"
     "    Features can be enabled or disabled, either globally or limited to\n"
-    "    specific character ranges.\n"
+    "    specific character ranges.  The format for specifying feature settings\n"
+    "    follows.  All valid CSS font-feature-settings values other than 'normal'\n"
+    "    and 'inherited' are also accepted, though, not documented below.\n"
     "\n"
     "    The range indices refer to the positions between Unicode characters,\n"
     "    unless the --utf8-clusters is provided, in which case range indices\n"
commit 6e69200a2aadbc6bba35ffb4a058c14286b84f46
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 12:30:47 2014 -0400

    Fix snprintf() format
    
    Patch from Maks Naumov.
    Fixes https://github.com/behdad/harfbuzz/pull/22

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index efe3bff..812cf59 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -257,18 +257,18 @@ hb_feature_to_string (hb_feature_t *feature,
   {
     s[len++] = '[';
     if (feature->start)
-      len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%d", feature->start));
+      len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->start));
     if (feature->end != feature->start + 1) {
       s[len++] = ':';
       if (feature->end != (unsigned int) -1)
-	len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%d", feature->end));
+	len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->end));
     }
     s[len++] = ']';
   }
   if (feature->value > 1)
   {
     s[len++] = '=';
-    len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%d", feature->value));
+    len += MAX (0, snprintf (s + len, ARRAY_LENGTH (s) - len, "%u", feature->value));
   }
   assert (len < ARRAY_LENGTH (s));
   len = MIN (len, size - 1);
commit 5c5cdbbdf8be231c433e21b050a6c6991d327b61
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 12:21:49 2014 -0400

    Make sure broken feature strings are not partially parsed
    
    If user doesn't check hb_feature_from_string() return value, we
    don't want them to end up see the partially-parsed feature.

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index f5a4ef2..efe3bff 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -37,8 +37,7 @@
 static bool
 parse_space (const char **pp, const char *end)
 {
-  char c;
-  while (*pp < end && (c = **pp, ISSPACE (c)))
+  while (*pp < end && ISSPACE (**pp))
     (*pp)++;
   return true;
 }
@@ -201,7 +200,7 @@ parse_one_feature (const char **pp, const char *end, hb_feature_t *feature)
  * hb_feature_from_string:
  * @str: (array length=len):
  * @len: 
- * @feature: (out):
+ * @feature: (out) (allow-none):
  *
  * 
  *
@@ -213,10 +212,21 @@ hb_bool_t
 hb_feature_from_string (const char *str, int len,
 			hb_feature_t *feature)
 {
+  hb_feature_t feat;
+
   if (len < 0)
     len = strlen (str);
 
-  return parse_one_feature (&str, str + len, feature);
+  if (likely (parse_one_feature (&str, str + len, &feat)))
+  {
+    if (feature)
+      *feature = feat;
+    return true;
+  }
+
+  if (feature)
+    memset (feature, 0, sizeof (*feature));
+  return false;
 }
 
 /**
commit a795fe637846e0d9561d2f7cdd84cfafd58b23a7
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 12:15:33 2014 -0400

    Allow quotation marks around feature tag in hb_feature_from_string()
    
    With this, I believe we accept CSS feature strings completely.

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index 2ed6ce9..f5a4ef2 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -117,16 +117,34 @@ parse_feature_tag (const char **pp, const char *end, hb_feature_t *feature)
 {
   parse_space (pp, end);
 
-  const char *p = *pp;
-  char c;
+  char quote = 0;
+
+  if (*pp < end && (**pp == '\'' || **pp == '"'))
+  {
+    quote = **pp;
+    (*pp)++;
+  }
 
-  while (*pp < end && (c = **pp, ISALNUM(c)))
+  const char *p = *pp;
+  while (*pp < end && ISALNUM(**pp))
     (*pp)++;
 
   if (p == *pp || *pp - p > 4)
     return false;
 
   feature->tag = hb_tag_from_string (p, *pp - p);
+
+  if (quote)
+  {
+    /* CSS expects exactly four bytes.  And we only allow quotations for
+     * CSS compatibility.  So, enforce the length. */
+     if (*pp - p != 4)
+       return false;
+    if (*pp == end || **pp != quote)
+      return false;
+    (*pp)++;
+  }
+
   return true;
 }
 
commit 3f6461847412e78bcddc8eba97200f3afcde869a
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 12:04:27 2014 -0400

    Allow space at the end of feature string with values, eg 'dlig=1 '

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index 94c6f72..2ed6ce9 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -34,12 +34,13 @@
 #include "hb-font-private.hh"
 
 
-static void
+static bool
 parse_space (const char **pp, const char *end)
 {
   char c;
   while (*pp < end && (c = **pp, ISSPACE (c)))
     (*pp)++;
+  return true;
 }
 
 static bool
@@ -174,6 +175,7 @@ parse_one_feature (const char **pp, const char *end, hb_feature_t *feature)
 	 parse_feature_tag (pp, end, feature) &&
 	 parse_feature_indices (pp, end, feature) &&
 	 parse_feature_value_postfix (pp, end, feature) &&
+	 parse_space (pp, end) &&
 	 *pp == end;
 }
 
commit f31f7d2259dd8edffc070af55938cb7aa23514c1
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 12:03:52 2014 -0400

    Minor

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index 93311b4..94c6f72 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -42,7 +42,7 @@ parse_space (const char **pp, const char *end)
     (*pp)++;
 }
 
-static hb_bool_t
+static bool
 parse_char (const char **pp, const char *end, char c)
 {
   parse_space (pp, end);
@@ -54,7 +54,7 @@ parse_char (const char **pp, const char *end, char c)
   return true;
 }
 
-static hb_bool_t
+static bool
 parse_uint (const char **pp, const char *end, unsigned int *pv)
 {
   char buf[32];
@@ -78,7 +78,7 @@ parse_uint (const char **pp, const char *end, unsigned int *pv)
   return true;
 }
 
-static hb_bool_t
+static bool
 parse_bool (const char **pp, const char *end, unsigned int *pv)
 {
   parse_space (pp, end);
@@ -98,7 +98,7 @@ parse_bool (const char **pp, const char *end, unsigned int *pv)
   return true;
 }
 
-static hb_bool_t
+static bool
 parse_feature_value_prefix (const char **pp, const char *end, hb_feature_t *feature)
 {
   if (parse_char (pp, end, '-'))
@@ -111,7 +111,7 @@ parse_feature_value_prefix (const char **pp, const char *end, hb_feature_t *feat
   return true;
 }
 
-static hb_bool_t
+static bool
 parse_feature_tag (const char **pp, const char *end, hb_feature_t *feature)
 {
   parse_space (pp, end);
@@ -129,12 +129,12 @@ parse_feature_tag (const char **pp, const char *end, hb_feature_t *feature)
   return true;
 }
 
-static hb_bool_t
+static bool
 parse_feature_indices (const char **pp, const char *end, hb_feature_t *feature)
 {
   parse_space (pp, end);
 
-  hb_bool_t has_start;
+  bool has_start;
 
   feature->start = 0;
   feature->end = (unsigned int) -1;
@@ -154,7 +154,7 @@ parse_feature_indices (const char **pp, const char *end, hb_feature_t *feature)
   return parse_char (pp, end, ']');
 }
 
-static hb_bool_t
+static bool
 parse_feature_value_postfix (const char **pp, const char *end, hb_feature_t *feature)
 {
   bool had_equal = parse_char (pp, end, '=');
@@ -167,7 +167,7 @@ parse_feature_value_postfix (const char **pp, const char *end, hb_feature_t *fea
 }
 
 
-static hb_bool_t
+static bool
 parse_one_feature (const char **pp, const char *end, hb_feature_t *feature)
 {
   return parse_feature_value_prefix (pp, end, feature) &&
commit 60cb18a5dea2d30793f89e80995bb729c014864a
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 12:01:22 2014 -0400

    Allow on/off in hb_feature_from_string()
    
    We now allow things like "dlig on" / "dlig=on".

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index 794cc1c..93311b4 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -79,6 +79,26 @@ parse_uint (const char **pp, const char *end, unsigned int *pv)
 }
 
 static hb_bool_t
+parse_bool (const char **pp, const char *end, unsigned int *pv)
+{
+  parse_space (pp, end);
+
+  const char *p = *pp;
+  while (*pp < end && ISALPHA(**pp))
+    (*pp)++;
+
+  /* CSS allows on/off as aliases 1/0. */
+  if (*pp - p == 2 || 0 == strncmp (p, "on", 2))
+    *pv = 1;
+  else if (*pp - p == 3 || 0 == strncmp (p, "off", 2))
+    *pv = 0;
+  else
+    return false;
+
+  return true;
+}
+
+static hb_bool_t
 parse_feature_value_prefix (const char **pp, const char *end, hb_feature_t *feature)
 {
   if (parse_char (pp, end, '-'))
@@ -138,8 +158,10 @@ static hb_bool_t
 parse_feature_value_postfix (const char **pp, const char *end, hb_feature_t *feature)
 {
   bool had_equal = parse_char (pp, end, '=');
-  bool had_value = parse_uint (pp, end, &feature->value);
-  /* If there was an equal-sign, then there *must* be a value.
+  bool had_value = parse_uint (pp, end, &feature->value) ||
+                   parse_bool (pp, end, &feature->value);
+  /* CSS doesn't use equal-sign between tag and value.
+   * If there was an equal-sign, then there *must* be a value.
    * A value without an eqaul-sign is ok, but not required. */
   return !had_equal || had_value;
 }
commit d9e618eca9e01c2eb6db65504af3f73be370a1e7
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 11:56:01 2014 -0400

    Remove duplicate definition of ISALNUM
    
    It's defined in hb-private.h already.

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index 34298a1..794cc1c 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -99,10 +99,8 @@ parse_feature_tag (const char **pp, const char *end, hb_feature_t *feature)
   const char *p = *pp;
   char c;
 
-#define ISALNUM(c) (('a' <= (c) && (c) <= 'z') || ('A' <= (c) && (c) <= 'Z') || ('0' <= (c) && (c) <= '9'))
   while (*pp < end && (c = **pp, ISALNUM(c)))
     (*pp)++;
-#undef ISALNUM
 
   if (p == *pp || *pp - p > 4)
     return false;
commit 2ee5f665ded86147acedc400153c0b3a90fe07c6
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 11:53:46 2014 -0400

    Fix parsing of features like "- liga" (with the space)

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index b4d3004..34298a1 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -94,11 +94,11 @@ parse_feature_value_prefix (const char **pp, const char *end, hb_feature_t *feat
 static hb_bool_t
 parse_feature_tag (const char **pp, const char *end, hb_feature_t *feature)
 {
+  parse_space (pp, end);
+
   const char *p = *pp;
   char c;
 
-  parse_space (pp, end);
-
 #define ISALNUM(c) (('a' <= (c) && (c) <= 'z') || ('A' <= (c) && (c) <= 'Z') || ('0' <= (c) && (c) <= '9'))
   while (*pp < end && (c = **pp, ISALNUM(c)))
     (*pp)++;
commit e15fa7a8cffbe6a67b1048d7b87b7df77d8b1686
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 11:44:35 2014 -0400

    Do not require the '=' in hb_feature_from_string()
    
    Towards accepting CSS font-feature-settings strings.

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index a63a5c1..b4d3004 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -139,7 +139,11 @@ parse_feature_indices (const char **pp, const char *end, hb_feature_t *feature)
 static hb_bool_t
 parse_feature_value_postfix (const char **pp, const char *end, hb_feature_t *feature)
 {
-  return !parse_char (pp, end, '=') || parse_uint (pp, end, &feature->value);
+  bool had_equal = parse_char (pp, end, '=');
+  bool had_value = parse_uint (pp, end, &feature->value);
+  /* If there was an equal-sign, then there *must* be a value.
+   * A value without an eqaul-sign is ok, but not required. */
+  return !had_equal || had_value;
 }
 
 
commit f4fe9baefdb7e0ff9946f88b6f4b55738fa30cdf
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 11:39:55 2014 -0400

    Reject tags longer than 4 chars in hb_feature_from_string()

diff --git a/src/hb-shape.cc b/src/hb-shape.cc
index c1b7524..a63a5c1 100644
--- a/src/hb-shape.cc
+++ b/src/hb-shape.cc
@@ -104,7 +104,7 @@ parse_feature_tag (const char **pp, const char *end, hb_feature_t *feature)
     (*pp)++;
 #undef ISALNUM
 
-  if (p == *pp)
+  if (p == *pp || *pp - p > 4)
     return false;
 
   feature->tag = hb_tag_from_string (p, *pp - p);
commit 7e8c38954649c0bf2e6051d84ca08dce090ec169
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Fri Jul 25 11:18:11 2014 -0400

    Minor warnings fixes
    
    Some systems insist on -Wmissing-field-initializers.  We have too many,
    by design.  Fix a few easy ones.

diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh
index 046df97..475187b 100644
--- a/src/hb-open-type-private.hh
+++ b/src/hb-open-type-private.hh
@@ -289,7 +289,7 @@ template <typename Type>
 struct Sanitizer
 {
   static hb_blob_t *sanitize (hb_blob_t *blob) {
-    hb_sanitize_context_t c[1] = {{0}};
+    hb_sanitize_context_t c[1] = {{0, NULL, NULL, false, 0, NULL}};
     bool sane;
 
     /* TODO is_sane() stuff */
diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh
index 9b06300..d94ac50 100644
--- a/src/hb-ot-layout-private.hh
+++ b/src/hb-ot-layout-private.hh
@@ -127,7 +127,7 @@ struct hb_ot_layout_lookup_accelerator_t
   }
 
   template <typename TLookup>
-  inline void fini (const TLookup &lookup)
+  inline void fini (const TLookup &lookup HB_UNUSED)
   {
   }
 
diff --git a/src/hb-private.hh b/src/hb-private.hh
index b24c9d1..5a4ca69 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -284,7 +284,7 @@ typedef int (*hb_compare_func_t) (const void *, const void *);
 /* arrays and maps */
 
 
-#define HB_PREALLOCED_ARRAY_INIT {0}
+#define HB_PREALLOCED_ARRAY_INIT {0, 0, NULL}
 template <typename Type, unsigned int StaticSize=16>
 struct hb_prealloced_array_t
 {


More information about the HarfBuzz mailing list