options.hh revision 3530cc2d7c3b7102902cb0e38b0bf9f46188078d
13bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod/*
23bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * Copyright © 2011  Google, Inc.
33bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod *
43bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
53bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod *
63bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * Permission is hereby granted, without written agreement and without
73bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
83bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * software and its documentation for any purpose, provided that the
93bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * above copyright notice and the following two paragraphs appear in
103bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * all copies of this software.
113bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod *
123bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
133bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
143bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
153bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
163bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * DAMAGE.
173bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod *
183bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
193bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
203bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
213bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
223bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
233bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod *
243bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod * Google Author(s): Behdad Esfahbod
253bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod */
263bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
273bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod#ifndef OPTIONS_HH
283bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod#define OPTIONS_HH
293bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
303bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
318b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#ifdef HAVE_CONFIG_H
328b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include "config.h"
338b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#endif
348b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod
358b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <stdlib.h>
368b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <stddef.h>
378b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <string.h>
388b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <stdio.h>
398b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <math.h>
408b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <locale.h>
418b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <errno.h>
428b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <fcntl.h>
4352e7b1424a3613122e9ca30879298df42733acdaBehdad Esfahbod#ifdef HAVE_UNISTD_H
4452e7b1424a3613122e9ca30879298df42733acdaBehdad Esfahbod#include <unistd.h> /* for isatty() */
4552e7b1424a3613122e9ca30879298df42733acdaBehdad Esfahbod#endif
46e2aab4b5db88c368c11cee81368b9ad41399e585Behdad Esfahbod#if defined(_WIN32) || defined(__CYGWIN__)
47bc76449f51f20491a4540b4f240f5a3e0dcb20feBehdad Esfahbod#include <io.h> /* for setmode() under Windows */
488b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#endif
498b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod
508b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <hb.h>
51c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod#ifdef HAVE_OT
52c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod#include <hb-ot.h>
53c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod#endif
548b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <glib.h>
558b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod#include <glib/gprintf.h>
568b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod
57c2bc818706df56022c8bb922df2b741cb120f7e4Behdad Esfahbod#if !GLIB_CHECK_VERSION (2, 22, 0)
58c2bc818706df56022c8bb922df2b741cb120f7e4Behdad Esfahbod# define g_mapped_file_unref g_mapped_file_free
59c2bc818706df56022c8bb922df2b741cb120f7e4Behdad Esfahbod#endif
60c2bc818706df56022c8bb922df2b741cb120f7e4Behdad Esfahbod
618650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod
628650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod/* A few macros copied from hb-private.hh. */
638650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod
648650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod#if __GNUC__ >= 4
658650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod#define HB_UNUSED	__attribute__((unused))
668650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod#else
678650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod#define HB_UNUSED
688650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod#endif
698650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod
7069b84a8f6c789726815261c2e86692de7a65d6e8Behdad Esfahbod#undef MIN
7169b84a8f6c789726815261c2e86692de7a65d6e8Behdad Esfahbodtemplate <typename Type> static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; }
7269b84a8f6c789726815261c2e86692de7a65d6e8Behdad Esfahbod
7369b84a8f6c789726815261c2e86692de7a65d6e8Behdad Esfahbod#undef MAX
7469b84a8f6c789726815261c2e86692de7a65d6e8Behdad Esfahbodtemplate <typename Type> static inline Type MAX (const Type &a, const Type &b) { return a > b ? a : b; }
7569b84a8f6c789726815261c2e86692de7a65d6e8Behdad Esfahbod
768650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod#undef  ARRAY_LENGTH
778650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbodtemplate <typename Type, unsigned int n>
788650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbodstatic inline unsigned int ARRAY_LENGTH (const Type (&)[n]) { return n; }
798650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod/* A const version, but does not detect erratically being called on pointers. */
808650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod#define ARRAY_LENGTH_CONST(__array) ((signed int) (sizeof (__array) / sizeof (__array[0])))
818650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod
828650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod#define _ASSERT_STATIC1(_line, _cond)	HB_UNUSED typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
838650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod#define _ASSERT_STATIC0(_line, _cond)	_ASSERT_STATIC1 (_line, (_cond))
848650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod#define ASSERT_STATIC(_cond)		_ASSERT_STATIC0 (__LINE__, (_cond))
858650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod
8669b84a8f6c789726815261c2e86692de7a65d6e8Behdad Esfahbod
87ea5e8a02eb83ad19f3009b0008893f77ce113118Behdad Esfahbodvoid fail (hb_bool_t suggest_help, const char *format, ...) G_GNUC_NORETURN G_GNUC_PRINTF (2, 3);
888b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod
898b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod
90088c1e27c0fc0cdef999cf1f567e4d5eb2cfb2e4Behdad Esfahbodextern hb_bool_t debug;
91b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
92b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstruct option_group_t
93b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{
94b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  virtual void add_options (struct option_parser_t *parser) = 0;
95b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
96b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  virtual void pre_parse (GError **error G_GNUC_UNUSED) {};
97b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  virtual void post_parse (GError **error G_GNUC_UNUSED) {};
98b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod};
99b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
100b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
101b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstruct option_parser_t
102b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{
103b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  option_parser_t (const char *usage) {
104b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    memset (this, 0, sizeof (*this));
105b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    usage_str = usage;
106b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    context = g_option_context_new (usage);
1072306ad46dce1c53b0b1bfabdc04d70e3b99eabb7Behdad Esfahbod    to_free = g_ptr_array_new ();
108b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
109b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    add_main_options ();
110b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  }
111b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  ~option_parser_t (void) {
112b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    g_option_context_free (context);
1132306ad46dce1c53b0b1bfabdc04d70e3b99eabb7Behdad Esfahbod    g_ptr_array_foreach (to_free, (GFunc) g_free, NULL);
1142306ad46dce1c53b0b1bfabdc04d70e3b99eabb7Behdad Esfahbod    g_ptr_array_free (to_free, TRUE);
115b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  }
116b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
117b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  void add_main_options (void);
118b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
119b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  void add_group (GOptionEntry   *entries,
120b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod		  const gchar    *name,
121b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod		  const gchar    *description,
122b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod		  const gchar    *help_description,
123b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod		  option_group_t *option_group);
124b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
1252306ad46dce1c53b0b1bfabdc04d70e3b99eabb7Behdad Esfahbod  void free_later (char *p) {
1262306ad46dce1c53b0b1bfabdc04d70e3b99eabb7Behdad Esfahbod    g_ptr_array_add (to_free, p);
1272306ad46dce1c53b0b1bfabdc04d70e3b99eabb7Behdad Esfahbod  }
1282306ad46dce1c53b0b1bfabdc04d70e3b99eabb7Behdad Esfahbod
129b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  void parse (int *argc, char ***argv);
130b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
131b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  G_GNUC_NORETURN void usage (void) {
132b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    g_printerr ("Usage: %s [OPTION...] %s\n", g_get_prgname (), usage_str);
133b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    exit (1);
134b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  }
135b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
1362306ad46dce1c53b0b1bfabdc04d70e3b99eabb7Behdad Esfahbod  private:
137b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  const char *usage_str;
138b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  GOptionContext *context;
1392306ad46dce1c53b0b1bfabdc04d70e3b99eabb7Behdad Esfahbod  GPtrArray *to_free;
140b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod};
141b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
142b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
143912c5ff80a255edb8145b9db69e2ed828f8eab5cBehdad Esfahbod#define DEFAULT_MARGIN 16
144109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod#define DEFAULT_FORE "#000000"
145109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod#define DEFAULT_BACK "#FFFFFF"
146cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod#define FONT_SIZE_UPEM 0x7FFFFFFF
147cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod#define FONT_SIZE_NONE 0
148109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod
149b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstruct view_options_t : option_group_t
1503bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod{
151b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  view_options_t (option_parser_t *parser) {
152b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    annotate = false;
1533530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    fore = NULL;
1543530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    back = NULL;
155b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    line_space = 0;
156109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod    margin.t = margin.r = margin.b = margin.l = DEFAULT_MARGIN;
157b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
158b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    add_options (parser);
1593bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod  }
1603530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  ~view_options_t (void)
1613530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  {
1623530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (fore);
1633530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (back);
1643530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  }
1653bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
166b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  void add_options (option_parser_t *parser);
167bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod
168088c1e27c0fc0cdef999cf1f567e4d5eb2cfb2e4Behdad Esfahbod  hb_bool_t annotate;
1693530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *fore;
1703530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *back;
1713bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod  double line_space;
1723bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod  struct margin_t {
1733bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod    double t, r, b, l;
1743bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod  } margin;
175b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod};
1763bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
177109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod
178b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstruct shape_options_t : option_group_t
1793bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod{
180ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  shape_options_t (option_parser_t *parser)
181ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  {
182b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    direction = language = script = NULL;
183407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod    bot = eot = preserve_default_ignorables = false;
184b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    features = NULL;
185b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    num_features = 0;
186b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    shapers = NULL;
18795cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod    utf8_clusters = false;
188376d587f36b4ff10342ee6ca3bacd73532ea44c8Behdad Esfahbod    cluster_level = HB_BUFFER_CLUSTER_LEVEL_DEFAULT;
18939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod    normalize_glyphs = false;
19050067e280f381918b8e90b26df9e7bf20f98f0bdBehdad Esfahbod    num_iterations = 1;
191b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
192b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    add_options (parser);
1933bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod  }
194ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  ~shape_options_t (void)
195ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  {
1963530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (direction);
1973530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (language);
1983530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (script);
19990e312cb85df7a6dc350cb62138ab950790e3d15Behdad Esfahbod    free (features);
200ade7459ea7c75b4f33f7cfa43dd5bdfa0c18d6d5Behdad Esfahbod    g_strfreev (shapers);
20190e312cb85df7a6dc350cb62138ab950790e3d15Behdad Esfahbod  }
2023bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
203b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  void add_options (option_parser_t *parser);
204bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod
205ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  void setup_buffer (hb_buffer_t *buffer)
206ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  {
207516857eb51bbb79ff4adf44e3fefbf460f9ee8f8Behdad Esfahbod    hb_buffer_set_direction (buffer, hb_direction_from_string (direction, -1));
208516857eb51bbb79ff4adf44e3fefbf460f9ee8f8Behdad Esfahbod    hb_buffer_set_script (buffer, hb_script_from_string (script, -1));
209516857eb51bbb79ff4adf44e3fefbf460f9ee8f8Behdad Esfahbod    hb_buffer_set_language (buffer, hb_language_from_string (language, -1));
2104dc798de19c767b91fd3025c85593fa6809d1340Behdad Esfahbod    hb_buffer_set_flags (buffer, (hb_buffer_flags_t) (HB_BUFFER_FLAG_DEFAULT |
211407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod			 (bot ? HB_BUFFER_FLAG_BOT : 0) |
212407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod			 (eot ? HB_BUFFER_FLAG_EOT : 0) |
213407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod			 (preserve_default_ignorables ? HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES : 0)));
214376d587f36b4ff10342ee6ca3bacd73532ea44c8Behdad Esfahbod    hb_buffer_set_cluster_level (buffer, cluster_level);
215c462b32dcb883a7aca066af24c4d28c7a2b7fa28Behdad Esfahbod    hb_buffer_guess_segment_properties (buffer);
2164f4b114a5592c2f5d128ee795f159b438ad97829Behdad Esfahbod  }
2174f4b114a5592c2f5d128ee795f159b438ad97829Behdad Esfahbod
218321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod  void populate_buffer (hb_buffer_t *buffer, const char *text, int text_len,
219321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod			const char *text_before, const char *text_after)
220ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  {
2211172dc736280566426eb6dade1a886b2a0ca9aa4Behdad Esfahbod    hb_buffer_clear_contents (buffer);
222321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod    if (text_before) {
223321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod      unsigned int len = strlen (text_before);
224321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod      hb_buffer_add_utf8 (buffer, text_before, len, len, 0);
225321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod    }
226b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    hb_buffer_add_utf8 (buffer, text, text_len, 0, text_len);
227321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod    if (text_after) {
228321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod      hb_buffer_add_utf8 (buffer, text_after, -1, 0, 0);
229321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod    }
230d5300241680844f5625f32792f7dd7181ed05f9bBehdad Esfahbod
23195cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod    if (!utf8_clusters) {
23295cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod      /* Reset cluster values to refer to Unicode character index
23395cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod       * instead of UTF-8 index. */
23495cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod      unsigned int num_glyphs = hb_buffer_get_length (buffer);
23595cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod      hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, NULL);
23695cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod      for (unsigned int i = 0; i < num_glyphs; i++)
23795cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod      {
23895cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod	info->cluster = i;
23995cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod	info++;
24095cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod      }
241d5300241680844f5625f32792f7dd7181ed05f9bBehdad Esfahbod    }
242d5300241680844f5625f32792f7dd7181ed05f9bBehdad Esfahbod
2434f4b114a5592c2f5d128ee795f159b438ad97829Behdad Esfahbod    setup_buffer (buffer);
244ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  }
245ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod
246ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  hb_bool_t shape (hb_font_t *font, hb_buffer_t *buffer)
247ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  {
24839b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod    hb_bool_t res = hb_shape_full (font, buffer, features, num_features, shapers);
24939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod    if (normalize_glyphs)
25039b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod      hb_buffer_normalize_glyphs (buffer);
25139b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod    return res;
2524f4b114a5592c2f5d128ee795f159b438ad97829Behdad Esfahbod  }
2534f4b114a5592c2f5d128ee795f159b438ad97829Behdad Esfahbod
254c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod  void shape_closure (const char *text, int text_len,
255c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod		      hb_font_t *font, hb_buffer_t *buffer,
256ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod		      hb_set_t *glyphs)
257ae62166519291057316a9d15cea3f1570fcb5eafBehdad Esfahbod  {
258c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod    hb_buffer_reset (buffer);
259c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod    hb_buffer_add_utf8 (buffer, text, text_len, 0, text_len);
260c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod    setup_buffer (buffer);
261c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod    hb_ot_shape_glyphs_closure (font, buffer, features, num_features, glyphs);
262c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod  }
263c87b317f0eb118e67134e8e419a6d65e0fa40d30Behdad Esfahbod
264407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod  /* Buffer properties */
2653530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *direction;
2663530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *language;
2673530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *script;
268407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod
269407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod  /* Buffer flags */
270407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod  hb_bool_t bot;
271407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod  hb_bool_t eot;
272407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod  hb_bool_t preserve_default_ignorables;
273407f80d62589774f845ef1a6a0a7d841b09d57c6Behdad Esfahbod
2743bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod  hb_feature_t *features;
2753bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod  unsigned int num_features;
2763bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod  char **shapers;
27795cefdf96efe43a44133aa8a186155cf4e63e2b7Behdad Esfahbod  hb_bool_t utf8_clusters;
278376d587f36b4ff10342ee6ca3bacd73532ea44c8Behdad Esfahbod  hb_buffer_cluster_level_t cluster_level;
27939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod  hb_bool_t normalize_glyphs;
28050067e280f381918b8e90b26df9e7bf20f98f0bdBehdad Esfahbod  unsigned int num_iterations;
281b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod};
2823bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
283109cb382898f491eed733dba4ef5ba12de94aaf6Behdad Esfahbod
284b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstruct font_options_t : option_group_t
2853bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod{
286cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod  font_options_t (option_parser_t *parser,
287cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod		  int default_font_size_,
288cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod		  unsigned int subpixel_bits_) {
289cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod    default_font_size = default_font_size_;
290cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod    subpixel_bits = subpixel_bits_;
291b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    font_file = NULL;
292b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    face_index = 0;
293cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod    font_size_x = font_size_y = default_font_size;
2948650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod    font_funcs = NULL;
295b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
296b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    font = NULL;
297b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
298b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    add_options (parser);
299b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  }
300b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  ~font_options_t (void) {
3013530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (font_file);
3023530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (font_funcs);
303b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    hb_font_destroy (font);
3043bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod  }
3053bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
306b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  void add_options (option_parser_t *parser);
307b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
308b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  hb_font_t *get_font (void) const;
309bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod
3103530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *font_file;
3113bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod  int face_index;
312cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod  int default_font_size;
313cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod  unsigned int subpixel_bits;
314cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod  mutable double font_size_x;
315cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod  mutable double font_size_y;
3163530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *font_funcs;
3173bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
318b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  private:
319b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  mutable hb_font_t *font;
320b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod};
321b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
322b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
323b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstruct text_options_t : option_group_t
324b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{
325b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  text_options_t (option_parser_t *parser) {
326321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod    text_before = NULL;
327321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod    text_after = NULL;
328321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod
329b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    text = NULL;
330b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    text_file = NULL;
331b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
33255aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod    fp = NULL;
33355aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod    gs = NULL;
3343530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    line = NULL;
3353530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    line_len = (unsigned int) -1;
336b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
337b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    add_options (parser);
338b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  }
339b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  ~text_options_t (void) {
3403530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (text_before);
3413530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (text_after);
3423530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (text);
3433530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (text_file);
34455aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod    if (gs)
3450594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod      g_string_free (gs, true);
34655aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod    if (fp)
34755aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod      fclose (fp);
348b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  }
349b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
350b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  void add_options (option_parser_t *parser);
351b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
352b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  void post_parse (GError **error G_GNUC_UNUSED) {
353b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    if (text && text_file)
354b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod      g_set_error (error,
355b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod		   G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
35630874b4819a99cc84fa39e794266685e1b8735d2Behdad Esfahbod		   "Only one of text and text-file can be set");
357b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  };
358b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
359b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  const char *get_line (unsigned int *len);
360b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
3613530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *text_before;
3623530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *text_after;
363321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod
3643530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *text;
3653530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *text_file;
366b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
367b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  private:
36855aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod  FILE *fp;
36955aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod  GString *gs;
3703530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *line;
3713530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  unsigned int line_len;
372b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod};
373b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
374b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstruct output_options_t : option_group_t
375b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{
3769815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod  output_options_t (option_parser_t *parser,
377ea5e8a02eb83ad19f3009b0008893f77ce113118Behdad Esfahbod		    const char **supported_formats_ = NULL) {
378b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    output_file = NULL;
379b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    output_format = NULL;
3809815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod    supported_formats = supported_formats_;
3816bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2Behdad Esfahbod    explicit_output_format = false;
382b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
383f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod    fp = NULL;
384f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod
385b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    add_options (parser);
386b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  }
387f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod  ~output_options_t (void) {
3883530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (output_file);
3893530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod    g_free (output_format);
39055aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod    if (fp)
391f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod      fclose (fp);
392f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod  }
393b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
394b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  void add_options (option_parser_t *parser);
395b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
396b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  void post_parse (GError **error G_GNUC_UNUSED)
397b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod  {
3986bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2Behdad Esfahbod    if (output_format)
3996bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2Behdad Esfahbod      explicit_output_format = true;
4006bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2Behdad Esfahbod
401b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    if (output_file && !output_format) {
402b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod      output_format = strrchr (output_file, '.');
403b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod      if (output_format)
404b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod	  output_format++; /* skip the dot */
405b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod    }
406b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod
407f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod    if (output_file && 0 == strcmp (output_file, "-"))
408f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod      output_file = NULL; /* STDOUT */
409f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod  }
410f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod
411a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod  FILE *get_file_handle (void);
4123bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
4133530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *output_file;
4143530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod  char *output_format;
415ea5e8a02eb83ad19f3009b0008893f77ce113118Behdad Esfahbod  const char **supported_formats;
4166bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2Behdad Esfahbod  bool explicit_output_format;
417f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod
418f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod  mutable FILE *fp;
419b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod};
4203bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
4218b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbodstruct format_options_t : option_group_t
4228b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod{
4238b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod  format_options_t (option_parser_t *parser) {
4248b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod    show_glyph_names = true;
4258b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod    show_positions = true;
4268b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod    show_clusters = true;
427cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod    show_text = false;
428cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod    show_unicode = false;
429cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod    show_line_num = false;
430fdd1770e006ca2d2973c049177ceda87a575e07fBehdad Esfahbod    show_extents = false;
4318b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod
4328b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod    add_options (parser);
4338b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod  }
4348b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod
4358b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod  void add_options (option_parser_t *parser);
4368b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod
437cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod  void serialize_unicode (hb_buffer_t  *buffer,
438cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod			  GString      *gs);
439cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod  void serialize_glyphs (hb_buffer_t  *buffer,
440cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod			 hb_font_t    *font,
441f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod			 hb_buffer_serialize_format_t format,
442f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod			 hb_buffer_serialize_flags_t flags,
443cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod			 GString      *gs);
444cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod  void serialize_line_no (unsigned int  line_no,
445cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod			  GString      *gs);
4465db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod  void serialize_buffer_of_text (hb_buffer_t  *buffer,
4475db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod				 unsigned int  line_no,
4485db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod				 const char   *text,
4495db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod				 unsigned int  text_len,
4505db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod				 hb_font_t    *font,
4515db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod				 GString      *gs);
4525db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod  void serialize_message (unsigned int  line_no,
4535db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod			  const char   *msg,
4545db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod			  GString      *gs);
4555db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod  void serialize_buffer_of_glyphs (hb_buffer_t  *buffer,
4565db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod				   unsigned int  line_no,
4575db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod				   const char   *text,
4585db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod				   unsigned int  text_len,
4595db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod				   hb_font_t    *font,
460f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod				   hb_buffer_serialize_format_t output_format,
461f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod				   hb_buffer_serialize_flags_t format_flags,
4625db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod				   GString      *gs);
463cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod
4648b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod
465088c1e27c0fc0cdef999cf1f567e4d5eb2cfb2e4Behdad Esfahbod  hb_bool_t show_glyph_names;
466088c1e27c0fc0cdef999cf1f567e4d5eb2cfb2e4Behdad Esfahbod  hb_bool_t show_positions;
467088c1e27c0fc0cdef999cf1f567e4d5eb2cfb2e4Behdad Esfahbod  hb_bool_t show_clusters;
468cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod  hb_bool_t show_text;
469cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod  hb_bool_t show_unicode;
470cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod  hb_bool_t show_line_num;
471fdd1770e006ca2d2973c049177ceda87a575e07fBehdad Esfahbod  hb_bool_t show_extents;
4728b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod};
4738b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod
4743bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod
4753bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod#endif
476