Imported Upstream version 2.6.7
[platform/upstream/harfbuzz.git] / util / options.cc
index 43ff90a..ee09ac5 100644 (file)
@@ -116,7 +116,7 @@ pre_parse (GOptionContext *context G_GNUC_UNUSED,
 {
   option_group_t *option_group = (option_group_t *) data;
   option_group->pre_parse (error);
-  return *error == nullptr;
+  return !*error;
 }
 
 static gboolean
@@ -127,7 +127,7 @@ post_parse (GOptionContext *context G_GNUC_UNUSED,
 {
   option_group_t *option_group = static_cast<option_group_t *>(data);
   option_group->post_parse (error);
-  return *error == nullptr;
+  return !*error;
 }
 
 void
@@ -152,16 +152,40 @@ option_parser_t::parse (int *argc, char ***argv)
   GError *parse_error = nullptr;
   if (!g_option_context_parse (context, argc, argv, &parse_error))
   {
-    if (parse_error != nullptr) {
+    if (parse_error)
+    {
       fail (true, "%s", parse_error->message);
       //g_error_free (parse_error);
-    } else
+    }
+    else
       fail (true, "Option parse error");
   }
 }
 
 
 static gboolean
+parse_font_extents (const char *name G_GNUC_UNUSED,
+                   const char *arg,
+                   gpointer    data,
+                   GError    **error G_GNUC_UNUSED)
+{
+  view_options_t *view_opts = (view_options_t *) data;
+  view_options_t::font_extents_t &e = view_opts->font_extents;
+  switch (sscanf (arg, "%lf%*[ ,]%lf%*[ ,]%lf", &e.ascent, &e.descent, &e.line_gap)) {
+    case 1: HB_FALLTHROUGH;
+    case 2: HB_FALLTHROUGH;
+    case 3:
+      view_opts->have_font_extents = true;
+      return true;
+    default:
+      g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+                  "%s argument should be one to three space-separated numbers",
+                  name);
+      return false;
+  }
+}
+
+static gboolean
 parse_margin (const char *name G_GNUC_UNUSED,
              const char *arg,
              gpointer    data,
@@ -372,7 +396,7 @@ parse_unicodes (const char *name G_GNUC_UNUSED,
       {
        g_string_free (gs, TRUE);
        g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
-                  "Failed parsing Unicode values at: '%s'", s);
+                    "Failed parsing Unicode values at: '%s'", s);
        return false;
       }
 
@@ -397,6 +421,7 @@ view_options_t::add_options (option_parser_t *parser)
     {"background",     0, 0, G_OPTION_ARG_STRING,      &this->back,                    "Set background color (default: " DEFAULT_BACK ")",     "rrggbb/rrggbbaa"},
     {"foreground",     0, 0, G_OPTION_ARG_STRING,      &this->fore,                    "Set foreground color (default: " DEFAULT_FORE ")",     "rrggbb/rrggbbaa"},
     {"line-space",     0, 0, G_OPTION_ARG_DOUBLE,      &this->line_space,              "Set space between lines (default: 0)",                 "units"},
+    {"font-extents",   0, 0, G_OPTION_ARG_CALLBACK,    (gpointer) &parse_font_extents, "Set font ascent/descent/line-gap (default: auto)","one to three numbers"},
     {"margin",         0, 0, G_OPTION_ARG_CALLBACK,    (gpointer) &parse_margin,       "Margin around output (default: " G_STRINGIFY(DEFAULT_MARGIN) ")","one to four numbers"},
     {nullptr}
   };
@@ -624,7 +649,7 @@ output_options_t::add_options (option_parser_t *parser)
 {
   const char *text;
 
-  if (nullptr == supported_formats)
+  if (!supported_formats)
     text = "Set output serialization format";
   else
   {
@@ -746,7 +771,7 @@ text_options_t::get_line (unsigned int *len)
       line = text;
       line_len = text_len;
     }
-    if (line_len == (unsigned int) -1)
+    if (line_len == UINT_MAX)
       line_len = strlen (line);
 
     if (!line_len) {
@@ -915,7 +940,7 @@ format_options_t::serialize_glyphs (hb_buffer_t *buffer,
 
   while (start < num_glyphs)
   {
-    char buf[1024];
+    char buf[32768];
     unsigned int consumed;
     start += hb_buffer_serialize_glyphs (buffer, start, num_glyphs,
                                         buf, sizeof (buf), &consumed,