diff options
author | Youngbok Shin <youngb.shin@samsung.com> | 2018-06-26 11:15:52 +0900 |
---|---|---|
committer | Youngbok Shin <youngb.shin@samsung.com> | 2018-06-26 11:15:52 +0900 |
commit | b9f425ddd6223cd82b3d35f13fbd060d3c0c0e38 (patch) | |
tree | 87220edcaa6118811d062d77d0562a3f74c7f885 /util | |
parent | 1c272a48507bb3c7905aa30d8bf0d092b474f781 (diff) | |
download | harfbuzz-b9f425ddd6223cd82b3d35f13fbd060d3c0c0e38.tar.gz harfbuzz-b9f425ddd6223cd82b3d35f13fbd060d3c0c0e38.tar.bz2 harfbuzz-b9f425ddd6223cd82b3d35f13fbd060d3c0c0e38.zip |
Imported Upstream version 1.8.1upstream/1.8.1
Diffstat (limited to 'util')
-rw-r--r-- | util/Makefile.in | 3 | ||||
-rw-r--r-- | util/options.cc | 126 | ||||
-rw-r--r-- | util/options.hh | 6 | ||||
-rw-r--r-- | util/view-cairo.cc | 2 | ||||
-rw-r--r-- | util/view-cairo.hh | 3 |
5 files changed, 47 insertions, 93 deletions
diff --git a/util/Makefile.in b/util/Makefile.in index 21092cf..86678cf 100644 --- a/util/Makefile.in +++ b/util/Makefile.in @@ -96,7 +96,8 @@ bin_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) @HAVE_GLIB_TRUE@@HAVE_OT_TRUE@am__append_3 = hb-ot-shape-closure subdir = util ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/m4/ax_code_coverage.m4 \ +am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_link_flag.m4 \ + $(top_srcdir)/m4/ax_code_coverage.m4 \ $(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/gtk-doc.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ diff --git a/util/options.cc b/util/options.cc index db7115c..24dc41f 100644 --- a/util/options.cc +++ b/util/options.cc @@ -65,8 +65,6 @@ fail (hb_bool_t suggest_help, const char *format, ...) } -hb_bool_t debug = false; - static gchar * shapers_to_string (void) { @@ -107,7 +105,6 @@ option_parser_t::add_main_options (void) { {"version", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, (gpointer) &show_version, "Show version numbers", nullptr}, - {"debug", 0, 0, G_OPTION_ARG_NONE, &debug, "Free all resources before exit", nullptr}, {nullptr} }; g_option_context_add_main_entries (context, entries, nullptr); @@ -192,11 +189,29 @@ static gboolean parse_shapers (const char *name G_GNUC_UNUSED, const char *arg, gpointer data, - GError **error G_GNUC_UNUSED) + GError **error) { shape_options_t *shape_opts = (shape_options_t *) data; + char **shapers = g_strsplit (arg, ",", 0); + + for (char **shaper = shapers; *shaper; shaper++) { + bool found = false; + for (const char **hb_shaper = hb_shape_list_shapers (); *hb_shaper; hb_shaper++) { + if (strcmp (*shaper, *hb_shaper) == 0) { + found = true; + break; + } + } + if (!found) { + g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, + "Unknown or unsupported shaper: %s", *shaper); + g_strfreev (shapers); + return false; + } + } + g_strfreev (shape_opts->shapers); - shape_opts->shapers = g_strsplit (arg, ",", 0); + shape_opts->shapers = shapers; return true; } @@ -340,8 +355,10 @@ parse_unicodes (const char *name G_GNUC_UNUSED, while (s && *s) { - while (*s && strchr ("<+>{},;&#\\xXuUnNiI\n\t", *s)) + while (*s && strchr ("<+>{},;&#\\xXuUnNiI\n\t\v\f\r ", *s)) s++; + if (!*s) + break; errno = 0; hb_codepoint_t u = strtoul (s, &p, 16); @@ -629,74 +646,29 @@ font_options_t::get_font (void) const hb_blob_t *blob = nullptr; /* Create the blob */ - { - char *font_data; - unsigned int len = 0; - hb_destroy_func_t destroy; - void *user_data; - hb_memory_mode_t mm; - - /* This is a hell of a lot of code for just reading a file! */ - if (!font_file) - fail (true, "No font file set"); - - if (0 == strcmp (font_file, "-")) { - /* read it */ - GString *gs = g_string_new (nullptr); - char buf[BUFSIZ]; + if (!font_file) + fail (true, "No font file set"); + + if (0 == strcmp (font_file, "-")) { + /* read it */ + GString *gs = g_string_new (nullptr); + char buf[BUFSIZ]; #if defined(_WIN32) || defined(__CYGWIN__) - setmode (fileno (stdin), O_BINARY); + setmode (fileno (stdin), O_BINARY); #endif - while (!feof (stdin)) { - size_t ret = fread (buf, 1, sizeof (buf), stdin); - if (ferror (stdin)) - fail (false, "Failed reading font from standard input: %s", - strerror (errno)); - g_string_append_len (gs, buf, ret); - } - len = gs->len; - font_data = g_string_free (gs, false); - user_data = font_data; - destroy = (hb_destroy_func_t) g_free; - mm = HB_MEMORY_MODE_WRITABLE; - } else { - GError *error = nullptr; - GMappedFile *mf = g_mapped_file_new (font_file, false, &error); - if (mf) { - font_data = g_mapped_file_get_contents (mf); - len = g_mapped_file_get_length (mf); - if (len) { - destroy = (hb_destroy_func_t) g_mapped_file_unref; - user_data = (void *) mf; - mm = HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE; - } else - g_mapped_file_unref (mf); - } else { - fail (false, "%s", error->message); - //g_error_free (error); - } - if (!len) { - /* GMappedFile is buggy, it doesn't fail if file isn't regular. - * Try reading. - * https://bugzilla.gnome.org/show_bug.cgi?id=659212 */ - GError *error = nullptr; - gsize l; - if (g_file_get_contents (font_file, &font_data, &l, &error)) { - len = l; - destroy = (hb_destroy_func_t) g_free; - user_data = (void *) font_data; - mm = HB_MEMORY_MODE_WRITABLE; - } else { - fail (false, "%s", error->message); - //g_error_free (error); - } - } + while (!feof (stdin)) { + size_t ret = fread (buf, 1, sizeof (buf), stdin); + if (ferror (stdin)) + fail (false, "Failed reading font from standard input: %s", + strerror (errno)); + g_string_append_len (gs, buf, ret); } - - if (debug) - mm = HB_MEMORY_MODE_DUPLICATE; - - blob = hb_blob_create (font_data, len, mm, user_data, destroy); + char *font_data = g_string_free (gs, false); + blob = hb_blob_create (font_data, gs->len, + HB_MEMORY_MODE_WRITABLE, font_data, + (hb_destroy_func_t) g_free); + } else { + blob = hb_blob_create_from_file (font_file); } /* Create the face */ @@ -803,12 +775,6 @@ text_options_t::get_line (unsigned int *len) gs = g_string_new (nullptr); } -#ifdef HAVE_SETLINEBUF - setlinebuf (fp); -#else - setvbuf(fp, NULL, _IOLBF, BUFSIZ); -#endif - g_string_set_size (gs, 0); char buf[BUFSIZ]; while (fgets (buf, sizeof (buf), fp)) { @@ -846,12 +812,6 @@ output_options_t::get_file_handle (void) fail (false, "Cannot open output file `%s': %s", g_filename_display_name (output_file), strerror (errno)); -#ifdef HAVE_SETLINEBUF - setlinebuf (fp); -#else - setvbuf(fp, NULL, _IOLBF, BUFSIZ); -#endif - return fp; } diff --git a/util/options.hh b/util/options.hh index 467350a..8dfc842 100644 --- a/util/options.hh +++ b/util/options.hh @@ -52,14 +52,8 @@ #include <glib.h> #include <glib/gprintf.h> -#if !GLIB_CHECK_VERSION (2, 22, 0) -# define g_mapped_file_unref g_mapped_file_free -#endif - void fail (hb_bool_t suggest_help, const char *format, ...) G_GNUC_NORETURN G_GNUC_PRINTF (2, 3); -extern hb_bool_t debug; - struct option_group_t { virtual void add_options (struct option_parser_t *parser) = 0; diff --git a/util/view-cairo.cc b/util/view-cairo.cc index f4f2bc5..e8e334b 100644 --- a/util/view-cairo.cc +++ b/util/view-cairo.cc @@ -49,7 +49,7 @@ view_cairo_t::render (const font_options_t *font_opts) double leading = font_height + view_options.line_space; /* Calculate surface size. */ - double w, h; + double w = 0, h = 0; (vertical ? w : h) = (int) lines->len * leading - view_options.line_space; (vertical ? h : w) = 0; for (unsigned int i = 0; i < lines->len; i++) { diff --git a/util/view-cairo.hh b/util/view-cairo.hh index d28c3cd..00df68c 100644 --- a/util/view-cairo.hh +++ b/util/view-cairo.hh @@ -40,8 +40,7 @@ struct view_cairo_t direction (HB_DIRECTION_INVALID), lines (0), scale_bits (0) {} ~view_cairo_t (void) { - if (debug) - cairo_debug_reset_static_data (); + cairo_debug_reset_static_data (); } void init (hb_buffer_t *buffer, const font_options_t *font_opts) |