options.hh 2.9 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 30 31 32
/*
 * 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
 */

#include "common.hh"

#ifndef OPTIONS_HH
#define OPTIONS_HH


33 34 35 36
#define DEFAULT_MARGIN 18
#define DEFAULT_FORE "#000000"
#define DEFAULT_BACK "#FFFFFF"

B
Behdad Esfahbod 已提交
37 38 39 40
extern struct view_options_t
{
  view_options_t (void) {
    memset (this, 0, sizeof (*this));
41 42 43
    fore = DEFAULT_FORE;
    back = DEFAULT_BACK;
    margin.t = margin.r = margin.b = margin.l = DEFAULT_MARGIN;
B
Behdad Esfahbod 已提交
44 45 46 47 48 49 50 51 52 53 54
  }

  hb_bool_t annotate;
  const char *fore;
  const char *back;
  double line_space;
  struct margin_t {
    double t, r, b, l;
  } margin;
} view_opts[1];

55

B
Behdad Esfahbod 已提交
56 57 58 59 60
extern struct shape_options_t
{
  shape_options_t (void) {
    memset (this, 0, sizeof (*this));
  }
B
Behdad Esfahbod 已提交
61 62 63 64
  ~shape_options_t (void) {
    free (features);
    g_free (shapers);
  }
B
Behdad Esfahbod 已提交
65

B
Behdad Esfahbod 已提交
66
  void setup_buffer (hb_buffer_t *buffer) {
B
Behdad Esfahbod 已提交
67 68 69
    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));
B
Behdad Esfahbod 已提交
70 71 72 73 74 75 76
  }

  bool shape (hb_font_t *font, hb_buffer_t *buffer) {
    setup_buffer (buffer);
    return hb_shape_full (font, buffer, features, num_features, NULL, shapers);
  }

B
Behdad Esfahbod 已提交
77 78 79 80 81 82 83 84 85
  const char *text;
  const char *direction;
  const char *language;
  const char *script;
  hb_feature_t *features;
  unsigned int num_features;
  char **shapers;
} shape_opts[1];

86 87 88

#define DEFAULT_FONT_SIZE 36

B
Behdad Esfahbod 已提交
89 90 91 92
extern struct font_options_t
{
  font_options_t (void) {
    memset (this, 0, sizeof (*this));
93
    font_size = DEFAULT_FONT_SIZE;
B
Behdad Esfahbod 已提交
94 95 96 97 98 99 100 101
  }

  const char *font_file;
  int face_index;
  double font_size;
} font_opts[1];


102 103
extern const char *out_file;
extern hb_bool_t debug;
B
Behdad Esfahbod 已提交
104 105


106 107 108 109
void option_context_add_view_opts	(GOptionContext *context);
void option_context_add_shape_opts	(GOptionContext *context);
void option_context_add_font_opts	(GOptionContext *context);

B
Behdad Esfahbod 已提交
110 111 112 113
void parse_options (int argc, char *argv[]);


#endif