options.hh 17.1 KB
Newer Older
B
Behdad Esfahbod 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * Copyright © 2011  Google, Inc.
 *
 *  This is part of HarfBuzz, a text shaping library.
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Google Author(s): Behdad Esfahbod
 */

#ifndef OPTIONS_HH
#define OPTIONS_HH

30
#include "hb.hh"
B
Behdad Esfahbod 已提交
31 32 33 34 35

#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
36
#include <assert.h>
B
Behdad Esfahbod 已提交
37 38 39 40
#include <math.h>
#include <locale.h>
#include <errno.h>
#include <fcntl.h>
41 42 43
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* for isatty() */
#endif
B
Behdad Esfahbod 已提交
44
#if defined(_WIN32) || defined(__CYGWIN__)
45
#include <io.h> /* for setmode() under Windows */
B
Behdad Esfahbod 已提交
46 47 48
#endif

#include <hb.h>
49 50 51
#ifdef HAVE_OT
#include <hb-ot.h>
#endif
B
Behdad Esfahbod 已提交
52 53 54
#include <glib.h>
#include <glib/gprintf.h>

B
Behdad Esfahbod 已提交
55
void fail (hb_bool_t suggest_help, const char *format, ...) G_GNUC_NORETURN G_GNUC_PRINTF (2, 3);
B
Behdad Esfahbod 已提交
56

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
struct option_group_t
{
  virtual void add_options (struct option_parser_t *parser) = 0;

  virtual void pre_parse (GError **error G_GNUC_UNUSED) {};
  virtual void post_parse (GError **error G_GNUC_UNUSED) {};
};


struct option_parser_t
{
  option_parser_t (const char *usage) {
    memset (this, 0, sizeof (*this));
    usage_str = usage;
    context = g_option_context_new (usage);
B
Behdad Esfahbod 已提交
72
    to_free = g_ptr_array_new ();
73 74 75 76 77

    add_main_options ();
  }
  ~option_parser_t (void) {
    g_option_context_free (context);
B
Behdad Esfahbod 已提交
78
    g_ptr_array_foreach (to_free, (GFunc) g_free, nullptr);
B
Behdad Esfahbod 已提交
79
    g_ptr_array_free (to_free, TRUE);
80 81 82 83 84 85 86 87 88 89
  }

  void add_main_options (void);

  void add_group (GOptionEntry   *entries,
		  const gchar    *name,
		  const gchar    *description,
		  const gchar    *help_description,
		  option_group_t *option_group);

B
Behdad Esfahbod 已提交
90 91 92 93
  void free_later (char *p) {
    g_ptr_array_add (to_free, p);
  }

94 95 96 97 98 99 100
  void parse (int *argc, char ***argv);

  G_GNUC_NORETURN void usage (void) {
    g_printerr ("Usage: %s [OPTION...] %s\n", g_get_prgname (), usage_str);
    exit (1);
  }

B
Behdad Esfahbod 已提交
101
  private:
102 103
  const char *usage_str;
  GOptionContext *context;
B
Behdad Esfahbod 已提交
104
  GPtrArray *to_free;
105 106 107
};


B
Behdad Esfahbod 已提交
108
#define DEFAULT_MARGIN 16
109 110
#define DEFAULT_FORE "#000000"
#define DEFAULT_BACK "#FFFFFF"
111 112
#define FONT_SIZE_UPEM 0x7FFFFFFF
#define FONT_SIZE_NONE 0
113

114
struct view_options_t : option_group_t
B
Behdad Esfahbod 已提交
115
{
116 117
  view_options_t (option_parser_t *parser) {
    annotate = false;
B
Behdad Esfahbod 已提交
118 119
    fore = nullptr;
    back = nullptr;
120
    line_space = 0;
121
    margin.t = margin.r = margin.b = margin.l = DEFAULT_MARGIN;
122 123

    add_options (parser);
B
Behdad Esfahbod 已提交
124
  }
B
Behdad Esfahbod 已提交
125 126 127 128 129
  ~view_options_t (void)
  {
    g_free (fore);
    g_free (back);
  }
B
Behdad Esfahbod 已提交
130

131
  void add_options (option_parser_t *parser);
B
Behdad Esfahbod 已提交
132

B
Behdad Esfahbod 已提交
133
  hb_bool_t annotate;
B
Behdad Esfahbod 已提交
134 135
  char *fore;
  char *back;
B
Behdad Esfahbod 已提交
136 137 138 139
  double line_space;
  struct margin_t {
    double t, r, b, l;
  } margin;
140
};
B
Behdad Esfahbod 已提交
141

142

143
struct shape_options_t : option_group_t
B
Behdad Esfahbod 已提交
144
{
B
Behdad Esfahbod 已提交
145 146
  shape_options_t (option_parser_t *parser)
  {
B
Behdad Esfahbod 已提交
147
    direction = language = script = nullptr;
148
    bot = eot = preserve_default_ignorables = remove_default_ignorables = false;
B
Behdad Esfahbod 已提交
149
    features = nullptr;
150
    num_features = 0;
B
Behdad Esfahbod 已提交
151
    shapers = nullptr;
B
Behdad Esfahbod 已提交
152
    utf8_clusters = false;
153
    cluster_level = HB_BUFFER_CLUSTER_LEVEL_DEFAULT;
154
    normalize_glyphs = false;
155
    verify = false;
B
Behdad Esfahbod 已提交
156
    num_iterations = 1;
157 158

    add_options (parser);
B
Behdad Esfahbod 已提交
159
  }
B
Behdad Esfahbod 已提交
160 161
  ~shape_options_t (void)
  {
B
Behdad Esfahbod 已提交
162 163 164
    g_free (direction);
    g_free (language);
    g_free (script);
B
Behdad Esfahbod 已提交
165
    free (features);
B
Behdad Esfahbod 已提交
166
    g_strfreev (shapers);
B
Behdad Esfahbod 已提交
167
  }
B
Behdad Esfahbod 已提交
168

169
  void add_options (option_parser_t *parser);
B
Behdad Esfahbod 已提交
170

B
Behdad Esfahbod 已提交
171 172
  void setup_buffer (hb_buffer_t *buffer)
  {
B
Behdad Esfahbod 已提交
173 174 175
    hb_buffer_set_direction (buffer, hb_direction_from_string (direction, -1));
    hb_buffer_set_script (buffer, hb_script_from_string (script, -1));
    hb_buffer_set_language (buffer, hb_language_from_string (language, -1));
176 177 178 179 180 181 182
    hb_buffer_set_flags (buffer, (hb_buffer_flags_t)
				 (HB_BUFFER_FLAG_DEFAULT |
				  (bot ? HB_BUFFER_FLAG_BOT : 0) |
				  (eot ? HB_BUFFER_FLAG_EOT : 0) |
				  (preserve_default_ignorables ? HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES : 0) |
				  (remove_default_ignorables ? HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES : 0) |
				  0));
183
    hb_buffer_set_cluster_level (buffer, cluster_level);
184
    hb_buffer_guess_segment_properties (buffer);
B
Behdad Esfahbod 已提交
185 186
  }

187 188 189 190 191 192 193 194 195
  static void copy_buffer_properties (hb_buffer_t *dst, hb_buffer_t *src)
  {
    hb_segment_properties_t props;
    hb_buffer_get_segment_properties (src, &props);
    hb_buffer_set_segment_properties (dst, &props);
    hb_buffer_set_flags (dst, hb_buffer_get_flags (src));
    hb_buffer_set_cluster_level (dst, hb_buffer_get_cluster_level (src));
  }

196 197
  void populate_buffer (hb_buffer_t *buffer, const char *text, int text_len,
			const char *text_before, const char *text_after)
B
Behdad Esfahbod 已提交
198
  {
199
    hb_buffer_clear_contents (buffer);
200 201 202 203
    if (text_before) {
      unsigned int len = strlen (text_before);
      hb_buffer_add_utf8 (buffer, text_before, len, len, 0);
    }
204
    hb_buffer_add_utf8 (buffer, text, text_len, 0, text_len);
205 206 207
    if (text_after) {
      hb_buffer_add_utf8 (buffer, text_after, -1, 0, 0);
    }
208

B
Behdad Esfahbod 已提交
209 210 211 212
    if (!utf8_clusters) {
      /* Reset cluster values to refer to Unicode character index
       * instead of UTF-8 index. */
      unsigned int num_glyphs = hb_buffer_get_length (buffer);
B
Behdad Esfahbod 已提交
213
      hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, nullptr);
B
Behdad Esfahbod 已提交
214 215 216 217 218
      for (unsigned int i = 0; i < num_glyphs; i++)
      {
	info->cluster = i;
	info++;
      }
219 220
    }

B
Behdad Esfahbod 已提交
221
    setup_buffer (buffer);
B
Behdad Esfahbod 已提交
222 223
  }

B
Behdad Esfahbod 已提交
224
  hb_bool_t shape (hb_font_t *font, hb_buffer_t *buffer, const char **error=nullptr)
B
Behdad Esfahbod 已提交
225
  {
B
Behdad Esfahbod 已提交
226
    hb_buffer_t *text_buffer = nullptr;
227 228 229 230 231 232
    if (verify)
    {
      text_buffer = hb_buffer_create ();
      hb_buffer_append (text_buffer, buffer, 0, -1);
    }

233 234 235 236
    if (!hb_shape_full (font, buffer, features, num_features, shapers))
    {
      if (error)
        *error = "all shapers failed.";
B
Behdad Esfahbod 已提交
237
      goto fail;
238 239
    }

240 241
    if (normalize_glyphs)
      hb_buffer_normalize_glyphs (buffer);
242

243
    if (verify && !verify_buffer (buffer, text_buffer, font, error))
B
Behdad Esfahbod 已提交
244
      goto fail;
245

246 247 248
    if (text_buffer)
      hb_buffer_destroy (text_buffer);

249
    return true;
B
Behdad Esfahbod 已提交
250 251 252 253 254 255

  fail:
    if (text_buffer)
      hb_buffer_destroy (text_buffer);

    return false;
256 257
  }

258 259 260
  bool verify_buffer (hb_buffer_t  *buffer,
		      hb_buffer_t  *text_buffer,
		      hb_font_t    *font,
B
Behdad Esfahbod 已提交
261
		      const char  **error=nullptr)
262 263 264 265 266 267 268 269
  {
    if (!verify_buffer_monotone (buffer, error))
      return false;
    if (!verify_buffer_safe_to_break (buffer, text_buffer, font, error))
      return false;
    return true;
  }

B
Behdad Esfahbod 已提交
270
  bool verify_buffer_monotone (hb_buffer_t *buffer, const char **error=nullptr)
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
  {
    /* Check that clusters are monotone. */
    if (cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES ||
	cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS)
    {
      bool is_forward = HB_DIRECTION_IS_FORWARD (hb_buffer_get_direction (buffer));

      unsigned int num_glyphs;
      hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, &num_glyphs);

      for (unsigned int i = 1; i < num_glyphs; i++)
	if (info[i-1].cluster != info[i].cluster &&
	    (info[i-1].cluster < info[i].cluster) != is_forward)
	{
	  if (error)
	    *error = "clusters are not monotone.";
	  return false;
	}
    }

    return true;
B
Behdad Esfahbod 已提交
292 293
  }

294 295 296
  bool verify_buffer_safe_to_break (hb_buffer_t  *buffer,
				    hb_buffer_t  *text_buffer,
				    hb_font_t    *font,
B
Behdad Esfahbod 已提交
297
				    const char  **error=nullptr)
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
  {
    if (cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES &&
	cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS)
    {
      /* Cannot perform this check without monotone clusters.
       * Then again, unsafe-to-break flag is much harder to use without
       * monotone clusters. */
      return true;
    }

    /* Check that breaking up shaping at safe-to-break is indeed safe. */

    hb_buffer_t *fragment = hb_buffer_create ();
    hb_buffer_t *reconstruction = hb_buffer_create ();
    copy_buffer_properties (reconstruction, buffer);

    unsigned int num_glyphs;
    hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, &num_glyphs);

    unsigned int num_chars;
    hb_glyph_info_t *text = hb_buffer_get_glyph_infos (text_buffer, &num_chars);

    /* Chop text and shape fragments. */
    bool forward = HB_DIRECTION_IS_FORWARD (hb_buffer_get_direction (buffer));
    unsigned int start = 0;
    unsigned int text_start = forward ? 0 : num_chars;
    unsigned int text_end = text_start;
    for (unsigned int end = 1; end < num_glyphs + 1; end++)
    {
      if (end < num_glyphs &&
	  (info[end].cluster == info[end-1].cluster ||
	   info[end-(forward?0:1)].mask & HB_GLYPH_FLAG_UNSAFE_TO_BREAK))
	  continue;

      /* Shape segment corresponding to glyphs start..end. */
      if (end == num_glyphs)
      {
        if (forward)
	  text_end = num_chars;
	else
	  text_start = 0;
      }
      else
      {
	if (forward)
343 344 345
	{
	  unsigned int cluster = info[end].cluster;
	  while (text_end < num_chars && text[text_end].cluster < cluster)
346
	    text_end++;
347
	}
348
	else
349 350 351
	{
	  unsigned int cluster = info[end - 1].cluster;
	  while (text_start && text[text_start - 1].cluster >= cluster)
352
	    text_start--;
353
	}
354 355 356
      }
      assert (text_start < text_end);

357 358 359
      if (0)
	printf("start %d end %d text start %d end %d\n", start, end, text_start, text_end);

360 361
      hb_buffer_clear_contents (fragment);
      copy_buffer_properties (fragment, buffer);
362 363 364 365 366 367 368 369 370

      /* TODO: Add pre/post context text. */
      hb_buffer_flags_t flags = hb_buffer_get_flags (fragment);
      if (0 < text_start)
        flags = (hb_buffer_flags_t) (flags & ~HB_BUFFER_FLAG_BOT);
      if (text_end < num_chars)
        flags = (hb_buffer_flags_t) (flags & ~HB_BUFFER_FLAG_EOT);
      hb_buffer_set_flags (fragment, flags);

371 372 373 374 375
      hb_buffer_append (fragment, text_buffer, text_start, text_end);
      if (!hb_shape_full (font, fragment, features, num_features, shapers))
      {
	if (error)
	  *error = "all shapers failed while shaping fragment.";
B
Behdad Esfahbod 已提交
376 377
	hb_buffer_destroy (reconstruction);
	hb_buffer_destroy (fragment);
378 379 380 381 382 383 384 385 386 387 388
	return false;
      }
      hb_buffer_append (reconstruction, fragment, 0, -1);

      start = end;
      if (forward)
	text_start = text_end;
      else
	text_end = text_start;
    }

389
    bool ret = true;
390
    hb_buffer_diff_flags_t diff = hb_buffer_diff (reconstruction, buffer, (hb_codepoint_t) -1, 0);
391 392 393 394 395
    if (diff)
    {
      if (error)
	*error = "Safe-to-break test failed.";
      ret = false;
396

397 398 399
      /* Return the reconstructed result instead so it can be inspected. */
      hb_buffer_set_length (buffer, 0);
      hb_buffer_append (buffer, reconstruction, 0, -1);
400
    }
401 402 403 404

    hb_buffer_destroy (reconstruction);
    hb_buffer_destroy (fragment);

405
    return ret;
406 407
  }

408 409
  void shape_closure (const char *text, int text_len,
		      hb_font_t *font, hb_buffer_t *buffer,
B
Behdad Esfahbod 已提交
410 411
		      hb_set_t *glyphs)
  {
412 413 414 415 416 417
    hb_buffer_reset (buffer);
    hb_buffer_add_utf8 (buffer, text, text_len, 0, text_len);
    setup_buffer (buffer);
    hb_ot_shape_glyphs_closure (font, buffer, features, num_features, glyphs);
  }

418
  /* Buffer properties */
B
Behdad Esfahbod 已提交
419 420 421
  char *direction;
  char *language;
  char *script;
422 423 424 425 426

  /* Buffer flags */
  hb_bool_t bot;
  hb_bool_t eot;
  hb_bool_t preserve_default_ignorables;
427
  hb_bool_t remove_default_ignorables;
428

B
Behdad Esfahbod 已提交
429 430 431
  hb_feature_t *features;
  unsigned int num_features;
  char **shapers;
B
Behdad Esfahbod 已提交
432
  hb_bool_t utf8_clusters;
433
  hb_buffer_cluster_level_t cluster_level;
434
  hb_bool_t normalize_glyphs;
435
  hb_bool_t verify;
B
Behdad Esfahbod 已提交
436
  unsigned int num_iterations;
437
};
B
Behdad Esfahbod 已提交
438

439

440
struct font_options_t : option_group_t
B
Behdad Esfahbod 已提交
441
{
442 443
  font_options_t (option_parser_t *parser,
		  int default_font_size_,
B
Behdad Esfahbod 已提交
444 445
		  unsigned int subpixel_bits_)
  {
B
Behdad Esfahbod 已提交
446
    variations = nullptr;
B
Behdad Esfahbod 已提交
447
    num_variations = 0;
448
    default_font_size = default_font_size_;
449 450
    x_ppem = 0;
    y_ppem = 0;
E
Ebrahim Byagowi 已提交
451
    ptem = 0.;
452
    subpixel_bits = subpixel_bits_;
B
Behdad Esfahbod 已提交
453
    font_file = nullptr;
454
    face_index = 0;
455
    font_size_x = font_size_y = default_font_size;
B
Behdad Esfahbod 已提交
456
    font_funcs = nullptr;
457

458
    blob = nullptr;
B
Behdad Esfahbod 已提交
459
    font = nullptr;
460 461 462 463

    add_options (parser);
  }
  ~font_options_t (void) {
B
Behdad Esfahbod 已提交
464
    g_free (font_file);
B
Behdad Esfahbod 已提交
465
    free (variations);
B
Behdad Esfahbod 已提交
466
    g_free (font_funcs);
467
    hb_font_destroy (font);
B
Behdad Esfahbod 已提交
468 469
  }

470 471 472
  void add_options (option_parser_t *parser);

  hb_font_t *get_font (void) const;
B
Behdad Esfahbod 已提交
473

B
Behdad Esfahbod 已提交
474
  char *font_file;
475
  mutable hb_blob_t *blob;
B
Behdad Esfahbod 已提交
476
  int face_index;
B
Behdad Esfahbod 已提交
477 478
  hb_variation_t *variations;
  unsigned int num_variations;
479
  int default_font_size;
480 481 482
  int x_ppem;
  int y_ppem;
  double ptem;
483 484 485
  unsigned int subpixel_bits;
  mutable double font_size_x;
  mutable double font_size_y;
B
Behdad Esfahbod 已提交
486
  char *font_funcs;
B
Behdad Esfahbod 已提交
487

488
  private:
489 490 491 492 493 494 495
  mutable hb_font_t *font;
};


struct text_options_t : option_group_t
{
  text_options_t (option_parser_t *parser) {
B
Behdad Esfahbod 已提交
496 497
    text_before = nullptr;
    text_after = nullptr;
498

B
Behdad Esfahbod 已提交
499 500
    text = nullptr;
    text_file = nullptr;
501

B
Behdad Esfahbod 已提交
502 503 504
    fp = nullptr;
    gs = nullptr;
    line = nullptr;
B
Behdad Esfahbod 已提交
505
    line_len = (unsigned int) -1;
506 507 508 509

    add_options (parser);
  }
  ~text_options_t (void) {
B
Behdad Esfahbod 已提交
510 511 512 513
    g_free (text_before);
    g_free (text_after);
    g_free (text);
    g_free (text_file);
B
Behdad Esfahbod 已提交
514
    if (gs)
515
      g_string_free (gs, true);
B
Behdad Esfahbod 已提交
516 517
    if (fp)
      fclose (fp);
518 519 520 521 522 523 524 525
  }

  void add_options (option_parser_t *parser);

  void post_parse (GError **error G_GNUC_UNUSED) {
    if (text && text_file)
      g_set_error (error,
		   G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
526
		   "Only one of text and text-file can be set");
527 528 529 530
  };

  const char *get_line (unsigned int *len);

B
Behdad Esfahbod 已提交
531 532
  char *text_before;
  char *text_after;
533

B
Behdad Esfahbod 已提交
534 535
  char *text;
  char *text_file;
536 537

  private:
B
Behdad Esfahbod 已提交
538 539
  FILE *fp;
  GString *gs;
B
Behdad Esfahbod 已提交
540 541
  char *line;
  unsigned int line_len;
542 543 544 545
};

struct output_options_t : option_group_t
{
546
  output_options_t (option_parser_t *parser,
B
Behdad Esfahbod 已提交
547 548 549
		    const char **supported_formats_ = nullptr) {
    output_file = nullptr;
    output_format = nullptr;
550
    supported_formats = supported_formats_;
551
    explicit_output_format = false;
552

B
Behdad Esfahbod 已提交
553
    fp = nullptr;
554

555 556
    add_options (parser);
  }
557
  ~output_options_t (void) {
B
Behdad Esfahbod 已提交
558 559
    g_free (output_file);
    g_free (output_format);
B
Behdad Esfahbod 已提交
560
    if (fp)
561 562
      fclose (fp);
  }
563 564 565 566 567

  void add_options (option_parser_t *parser);

  void post_parse (GError **error G_GNUC_UNUSED)
  {
568 569 570
    if (output_format)
      explicit_output_format = true;

571 572 573
    if (output_file && !output_format) {
      output_format = strrchr (output_file, '.');
      if (output_format)
574
      {
575
	  output_format++; /* skip the dot */
576 577
	  output_format = strdup (output_format);
      }
578 579
    }

580
    if (output_file && 0 == strcmp (output_file, "-"))
B
Behdad Esfahbod 已提交
581
      output_file = nullptr; /* STDOUT */
582 583
  }

B
Behdad Esfahbod 已提交
584
  FILE *get_file_handle (void);
B
Behdad Esfahbod 已提交
585

B
Behdad Esfahbod 已提交
586 587
  char *output_file;
  char *output_format;
B
Behdad Esfahbod 已提交
588
  const char **supported_formats;
589
  bool explicit_output_format;
590 591

  mutable FILE *fp;
592
};
B
Behdad Esfahbod 已提交
593

B
Behdad Esfahbod 已提交
594 595 596 597 598
struct format_options_t : option_group_t
{
  format_options_t (option_parser_t *parser) {
    show_glyph_names = true;
    show_positions = true;
599
    show_advances = true;
B
Behdad Esfahbod 已提交
600
    show_clusters = true;
601 602
    show_text = false;
    show_unicode = false;
B
Behdad Esfahbod 已提交
603
    show_line_num = false;
604
    show_extents = false;
605
    show_flags = false;
606
    trace = false;
B
Behdad Esfahbod 已提交
607 608 609 610 611 612

    add_options (parser);
  }

  void add_options (option_parser_t *parser);

B
Behdad Esfahbod 已提交
613 614 615 616
  void serialize_unicode (hb_buffer_t  *buffer,
			  GString      *gs);
  void serialize_glyphs (hb_buffer_t  *buffer,
			 hb_font_t    *font,
617 618
			 hb_buffer_serialize_format_t format,
			 hb_buffer_serialize_flags_t flags,
B
Behdad Esfahbod 已提交
619 620 621
			 GString      *gs);
  void serialize_line_no (unsigned int  line_no,
			  GString      *gs);
622 623 624 625 626 627 628
  void serialize_buffer_of_text (hb_buffer_t  *buffer,
				 unsigned int  line_no,
				 const char   *text,
				 unsigned int  text_len,
				 hb_font_t    *font,
				 GString      *gs);
  void serialize_message (unsigned int  line_no,
629
			  const char   *type,
630 631 632 633 634 635 636
			  const char   *msg,
			  GString      *gs);
  void serialize_buffer_of_glyphs (hb_buffer_t  *buffer,
				   unsigned int  line_no,
				   const char   *text,
				   unsigned int  text_len,
				   hb_font_t    *font,
637 638
				   hb_buffer_serialize_format_t output_format,
				   hb_buffer_serialize_flags_t format_flags,
639
				   GString      *gs);
B
Behdad Esfahbod 已提交
640

B
Behdad Esfahbod 已提交
641

B
Behdad Esfahbod 已提交
642 643
  hb_bool_t show_glyph_names;
  hb_bool_t show_positions;
644
  hb_bool_t show_advances;
B
Behdad Esfahbod 已提交
645
  hb_bool_t show_clusters;
646 647
  hb_bool_t show_text;
  hb_bool_t show_unicode;
B
Behdad Esfahbod 已提交
648
  hb_bool_t show_line_num;
649
  hb_bool_t show_extents;
650
  hb_bool_t show_flags;
651
  hb_bool_t trace;
B
Behdad Esfahbod 已提交
652 653
};

R
Rod Sheeter 已提交
654 655 656 657
struct subset_options_t : option_group_t
{
  subset_options_t (option_parser_t *parser)
  {
658
    drop_hints = false;
R
Rod Sheeter 已提交
659 660 661 662 663 664

    add_options (parser);
  }

  void add_options (option_parser_t *parser);

665
  hb_bool_t drop_hints;
R
Rod Sheeter 已提交
666 667
};

668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684
/* fallback implementation for scalbn()/scalbnf() for pre-2013 MSVC */
#if defined (_MSC_VER) && (_MSC_VER < 1800)

#ifndef FLT_RADIX
#define FLT_RADIX 2
#endif

__inline long double scalbn (long double x, int exp)
{
  return x * (pow ((long double) FLT_RADIX, exp));
}

__inline float scalbnf (float x, int exp)
{
  return x * (pow ((float) FLT_RADIX, exp));
}
#endif
B
Behdad Esfahbod 已提交
685 686

#endif