blob: 919e4f8b2759bdbaa3cae8524d41346c97a5f894 [file] [log] [blame]
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +02001/*
2 * Copyright © 2011 Google, Inc.
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 *
24 * Google Author(s): Behdad Esfahbod
25 */
26
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +020027#ifndef OPTIONS_HH
28#define OPTIONS_HH
29
30
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -040031#ifdef HAVE_CONFIG_H
32#include "config.h"
33#endif
34
35#include <stdlib.h>
36#include <stddef.h>
37#include <string.h>
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -040038#include <stdio.h>
39#include <math.h>
40#include <locale.h>
41#include <errno.h>
42#include <fcntl.h>
Behdad Esfahbod52e7b142012-05-13 02:02:58 +020043#ifdef HAVE_UNISTD_H
44#include <unistd.h> /* for isatty() */
45#endif
Behdad Esfahbode2aab4b2013-02-12 15:35:32 -050046#if defined(_WIN32) || defined(__CYGWIN__)
Behdad Esfahbodbc764492013-01-31 18:18:05 -050047#include <io.h> /* for setmode() under Windows */
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -040048#endif
49
50#include <hb.h>
Behdad Esfahbodc87b3172012-05-15 23:53:18 -040051#ifdef HAVE_OT
52#include <hb-ot.h>
53#endif
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -040054#include <glib.h>
55#include <glib/gprintf.h>
56
Behdad Esfahbodc2bc8182013-10-27 23:36:35 +010057#if !GLIB_CHECK_VERSION (2, 22, 0)
58# define g_mapped_file_unref g_mapped_file_free
59#endif
60
Behdad Esfahbod8650def2014-07-05 15:50:18 -040061
62/* A few macros copied from hb-private.hh. */
63
64#if __GNUC__ >= 4
65#define HB_UNUSED __attribute__((unused))
66#else
67#define HB_UNUSED
68#endif
69
Behdad Esfahbod69b84a82012-04-12 15:50:40 -040070#undef MIN
71template <typename Type> static inline Type MIN (const Type &a, const Type &b) { return a < b ? a : b; }
72
73#undef MAX
74template <typename Type> static inline Type MAX (const Type &a, const Type &b) { return a > b ? a : b; }
75
Behdad Esfahbod8650def2014-07-05 15:50:18 -040076#undef ARRAY_LENGTH
77template <typename Type, unsigned int n>
78static inline unsigned int ARRAY_LENGTH (const Type (&)[n]) { return n; }
79/* A const version, but does not detect erratically being called on pointers. */
80#define ARRAY_LENGTH_CONST(__array) ((signed int) (sizeof (__array) / sizeof (__array[0])))
81
82#define _ASSERT_STATIC1(_line, _cond) HB_UNUSED typedef int _static_assert_on_line_##_line##_failed[(_cond)?1:-1]
83#define _ASSERT_STATIC0(_line, _cond) _ASSERT_STATIC1 (_line, (_cond))
84#define ASSERT_STATIC(_cond) _ASSERT_STATIC0 (__LINE__, (_cond))
85
Behdad Esfahbod69b84a82012-04-12 15:50:40 -040086
Behdad Esfahbodea5e8a02014-03-19 15:38:02 -070087void fail (hb_bool_t suggest_help, const char *format, ...) G_GNUC_NORETURN G_GNUC_PRINTF (2, 3);
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -040088
89
Behdad Esfahbod088c1e22011-09-20 14:43:55 -040090extern hb_bool_t debug;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040091
92struct option_group_t
93{
94 virtual void add_options (struct option_parser_t *parser) = 0;
95
96 virtual void pre_parse (GError **error G_GNUC_UNUSED) {};
97 virtual void post_parse (GError **error G_GNUC_UNUSED) {};
98};
99
100
101struct option_parser_t
102{
103 option_parser_t (const char *usage) {
104 memset (this, 0, sizeof (*this));
105 usage_str = usage;
106 context = g_option_context_new (usage);
Behdad Esfahbod2306ad42014-07-04 18:09:29 -0400107 to_free = g_ptr_array_new ();
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400108
109 add_main_options ();
110 }
111 ~option_parser_t (void) {
112 g_option_context_free (context);
Behdad Esfahbod2306ad42014-07-04 18:09:29 -0400113 g_ptr_array_foreach (to_free, (GFunc) g_free, NULL);
114 g_ptr_array_free (to_free, TRUE);
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400115 }
116
117 void add_main_options (void);
118
119 void add_group (GOptionEntry *entries,
120 const gchar *name,
121 const gchar *description,
122 const gchar *help_description,
123 option_group_t *option_group);
124
Behdad Esfahbod2306ad42014-07-04 18:09:29 -0400125 void free_later (char *p) {
126 g_ptr_array_add (to_free, p);
127 }
128
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400129 void parse (int *argc, char ***argv);
130
131 G_GNUC_NORETURN void usage (void) {
132 g_printerr ("Usage: %s [OPTION...] %s\n", g_get_prgname (), usage_str);
133 exit (1);
134 }
135
Behdad Esfahbod2306ad42014-07-04 18:09:29 -0400136 private:
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400137 const char *usage_str;
138 GOptionContext *context;
Behdad Esfahbod2306ad42014-07-04 18:09:29 -0400139 GPtrArray *to_free;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400140};
141
142
Behdad Esfahbod912c5ff2012-05-13 12:51:02 +0200143#define DEFAULT_MARGIN 16
Behdad Esfahbod109cb382011-09-08 16:00:04 -0400144#define DEFAULT_FORE "#000000"
145#define DEFAULT_BACK "#FFFFFF"
Behdad Esfahbodcd4eb962015-01-20 12:30:45 -0800146#define FONT_SIZE_UPEM 0x7FFFFFFF
147#define FONT_SIZE_NONE 0
Behdad Esfahbod109cb382011-09-08 16:00:04 -0400148
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400149struct view_options_t : option_group_t
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200150{
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400151 view_options_t (option_parser_t *parser) {
152 annotate = false;
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800153 fore = NULL;
154 back = NULL;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400155 line_space = 0;
Behdad Esfahbod109cb382011-09-08 16:00:04 -0400156 margin.t = margin.r = margin.b = margin.l = DEFAULT_MARGIN;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400157
158 add_options (parser);
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200159 }
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800160 ~view_options_t (void)
161 {
162 g_free (fore);
163 g_free (back);
164 }
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200165
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400166 void add_options (option_parser_t *parser);
Behdad Esfahbodbc4b07b2011-09-08 17:08:32 -0400167
Behdad Esfahbod088c1e22011-09-20 14:43:55 -0400168 hb_bool_t annotate;
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800169 char *fore;
170 char *back;
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200171 double line_space;
172 struct margin_t {
173 double t, r, b, l;
174 } margin;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400175};
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200176
Behdad Esfahbod109cb382011-09-08 16:00:04 -0400177
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400178struct shape_options_t : option_group_t
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200179{
Behdad Esfahbodae621662012-06-02 12:21:19 -0400180 shape_options_t (option_parser_t *parser)
181 {
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400182 direction = language = script = NULL;
Behdad Esfahbod407f80d2012-11-13 15:33:27 -0800183 bot = eot = preserve_default_ignorables = false;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400184 features = NULL;
185 num_features = 0;
186 shapers = NULL;
Behdad Esfahbod95cefdf2012-04-16 18:08:20 -0400187 utf8_clusters = false;
Behdad Esfahbod376d5872015-07-22 16:51:12 +0100188 cluster_level = HB_BUFFER_CLUSTER_LEVEL_DEFAULT;
Behdad Esfahbod39b17832012-07-17 17:09:29 -0400189 normalize_glyphs = false;
Behdad Esfahbod50067e22013-04-11 16:31:01 -0400190 num_iterations = 1;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400191
192 add_options (parser);
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200193 }
Behdad Esfahbodae621662012-06-02 12:21:19 -0400194 ~shape_options_t (void)
195 {
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800196 g_free (direction);
197 g_free (language);
198 g_free (script);
Behdad Esfahbod90e312c2011-09-08 16:42:37 -0400199 free (features);
Behdad Esfahbodade74592012-08-06 19:42:47 -0700200 g_strfreev (shapers);
Behdad Esfahbod90e312c2011-09-08 16:42:37 -0400201 }
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200202
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400203 void add_options (option_parser_t *parser);
Behdad Esfahbodbc4b07b2011-09-08 17:08:32 -0400204
Behdad Esfahbodae621662012-06-02 12:21:19 -0400205 void setup_buffer (hb_buffer_t *buffer)
206 {
Behdad Esfahbod516857e2011-09-08 16:50:24 -0400207 hb_buffer_set_direction (buffer, hb_direction_from_string (direction, -1));
208 hb_buffer_set_script (buffer, hb_script_from_string (script, -1));
209 hb_buffer_set_language (buffer, hb_language_from_string (language, -1));
Behdad Esfahbod4dc798d2013-08-26 20:39:00 -0400210 hb_buffer_set_flags (buffer, (hb_buffer_flags_t) (HB_BUFFER_FLAG_DEFAULT |
Behdad Esfahbod407f80d2012-11-13 15:33:27 -0800211 (bot ? HB_BUFFER_FLAG_BOT : 0) |
212 (eot ? HB_BUFFER_FLAG_EOT : 0) |
213 (preserve_default_ignorables ? HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES : 0)));
Behdad Esfahbod376d5872015-07-22 16:51:12 +0100214 hb_buffer_set_cluster_level (buffer, cluster_level);
Behdad Esfahbodc462b322013-02-15 07:51:47 -0500215 hb_buffer_guess_segment_properties (buffer);
Behdad Esfahbod4f4b1142011-09-08 16:49:02 -0400216 }
217
Behdad Esfahbod321f73c2012-11-13 15:12:24 -0800218 void populate_buffer (hb_buffer_t *buffer, const char *text, int text_len,
219 const char *text_before, const char *text_after)
Behdad Esfahbodae621662012-06-02 12:21:19 -0400220 {
Behdad Esfahbod1172dc72013-01-07 16:46:37 -0600221 hb_buffer_clear_contents (buffer);
Behdad Esfahbod321f73c2012-11-13 15:12:24 -0800222 if (text_before) {
223 unsigned int len = strlen (text_before);
224 hb_buffer_add_utf8 (buffer, text_before, len, len, 0);
225 }
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400226 hb_buffer_add_utf8 (buffer, text, text_len, 0, text_len);
Behdad Esfahbod321f73c2012-11-13 15:12:24 -0800227 if (text_after) {
228 hb_buffer_add_utf8 (buffer, text_after, -1, 0, 0);
229 }
Behdad Esfahbodd5300242012-01-21 19:07:22 -0500230
Behdad Esfahbod95cefdf2012-04-16 18:08:20 -0400231 if (!utf8_clusters) {
232 /* Reset cluster values to refer to Unicode character index
233 * instead of UTF-8 index. */
234 unsigned int num_glyphs = hb_buffer_get_length (buffer);
235 hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, NULL);
236 for (unsigned int i = 0; i < num_glyphs; i++)
237 {
238 info->cluster = i;
239 info++;
240 }
Behdad Esfahbodd5300242012-01-21 19:07:22 -0500241 }
242
Behdad Esfahbod4f4b1142011-09-08 16:49:02 -0400243 setup_buffer (buffer);
Behdad Esfahbodae621662012-06-02 12:21:19 -0400244 }
245
246 hb_bool_t shape (hb_font_t *font, hb_buffer_t *buffer)
247 {
Behdad Esfahbod39b17832012-07-17 17:09:29 -0400248 hb_bool_t res = hb_shape_full (font, buffer, features, num_features, shapers);
249 if (normalize_glyphs)
250 hb_buffer_normalize_glyphs (buffer);
251 return res;
Behdad Esfahbod4f4b1142011-09-08 16:49:02 -0400252 }
253
Behdad Esfahbodc87b3172012-05-15 23:53:18 -0400254 void shape_closure (const char *text, int text_len,
255 hb_font_t *font, hb_buffer_t *buffer,
Behdad Esfahbodae621662012-06-02 12:21:19 -0400256 hb_set_t *glyphs)
257 {
Behdad Esfahbodc87b3172012-05-15 23:53:18 -0400258 hb_buffer_reset (buffer);
259 hb_buffer_add_utf8 (buffer, text, text_len, 0, text_len);
260 setup_buffer (buffer);
261 hb_ot_shape_glyphs_closure (font, buffer, features, num_features, glyphs);
262 }
263
Behdad Esfahbod407f80d2012-11-13 15:33:27 -0800264 /* Buffer properties */
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800265 char *direction;
266 char *language;
267 char *script;
Behdad Esfahbod407f80d2012-11-13 15:33:27 -0800268
269 /* Buffer flags */
270 hb_bool_t bot;
271 hb_bool_t eot;
272 hb_bool_t preserve_default_ignorables;
273
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200274 hb_feature_t *features;
275 unsigned int num_features;
276 char **shapers;
Behdad Esfahbod95cefdf2012-04-16 18:08:20 -0400277 hb_bool_t utf8_clusters;
Behdad Esfahbod376d5872015-07-22 16:51:12 +0100278 hb_buffer_cluster_level_t cluster_level;
Behdad Esfahbod39b17832012-07-17 17:09:29 -0400279 hb_bool_t normalize_glyphs;
Behdad Esfahbod50067e22013-04-11 16:31:01 -0400280 unsigned int num_iterations;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400281};
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200282
Behdad Esfahbod109cb382011-09-08 16:00:04 -0400283
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400284struct font_options_t : option_group_t
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200285{
Behdad Esfahbodcd4eb962015-01-20 12:30:45 -0800286 font_options_t (option_parser_t *parser,
287 int default_font_size_,
288 unsigned int subpixel_bits_) {
289 default_font_size = default_font_size_;
290 subpixel_bits = subpixel_bits_;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400291 font_file = NULL;
292 face_index = 0;
Behdad Esfahbodcd4eb962015-01-20 12:30:45 -0800293 font_size_x = font_size_y = default_font_size;
Behdad Esfahbod8650def2014-07-05 15:50:18 -0400294 font_funcs = NULL;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400295
296 font = NULL;
297
298 add_options (parser);
299 }
300 ~font_options_t (void) {
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800301 g_free (font_file);
302 g_free (font_funcs);
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400303 hb_font_destroy (font);
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200304 }
305
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400306 void add_options (option_parser_t *parser);
307
308 hb_font_t *get_font (void) const;
Behdad Esfahbodbc4b07b2011-09-08 17:08:32 -0400309
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800310 char *font_file;
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200311 int face_index;
Behdad Esfahbodcd4eb962015-01-20 12:30:45 -0800312 int default_font_size;
313 unsigned int subpixel_bits;
314 mutable double font_size_x;
315 mutable double font_size_y;
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800316 char *font_funcs;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400317
318 private:
319 mutable hb_font_t *font;
320};
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200321
322
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400323struct text_options_t : option_group_t
324{
325 text_options_t (option_parser_t *parser) {
Behdad Esfahbod321f73c2012-11-13 15:12:24 -0800326 text_before = NULL;
327 text_after = NULL;
328
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400329 text = NULL;
330 text_file = NULL;
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200331
Behdad Esfahbod55aeb042011-09-16 02:08:36 -0400332 fp = NULL;
333 gs = NULL;
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800334 line = NULL;
335 line_len = (unsigned int) -1;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400336
337 add_options (parser);
338 }
339 ~text_options_t (void) {
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800340 g_free (text_before);
341 g_free (text_after);
342 g_free (text);
343 g_free (text_file);
Behdad Esfahbod55aeb042011-09-16 02:08:36 -0400344 if (gs)
Behdad Esfahbod0594a242012-06-05 20:35:40 -0400345 g_string_free (gs, true);
Behdad Esfahbod55aeb042011-09-16 02:08:36 -0400346 if (fp)
347 fclose (fp);
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400348 }
349
350 void add_options (option_parser_t *parser);
351
352 void post_parse (GError **error G_GNUC_UNUSED) {
353 if (text && text_file)
354 g_set_error (error,
355 G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
Behdad Esfahbod30874b42012-05-12 15:54:27 +0200356 "Only one of text and text-file can be set");
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400357 };
358
359 const char *get_line (unsigned int *len);
360
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800361 char *text_before;
362 char *text_after;
Behdad Esfahbod321f73c2012-11-13 15:12:24 -0800363
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800364 char *text;
365 char *text_file;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400366
367 private:
Behdad Esfahbod55aeb042011-09-16 02:08:36 -0400368 FILE *fp;
369 GString *gs;
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800370 char *line;
371 unsigned int line_len;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400372};
373
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400374struct output_options_t : option_group_t
375{
Behdad Esfahbod9815a882012-12-21 16:46:53 -0500376 output_options_t (option_parser_t *parser,
Behdad Esfahbodea5e8a02014-03-19 15:38:02 -0700377 const char **supported_formats_ = NULL) {
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400378 output_file = NULL;
379 output_format = NULL;
Behdad Esfahbod9815a882012-12-21 16:46:53 -0500380 supported_formats = supported_formats_;
Behdad Esfahbod6bad0922012-12-21 16:01:52 -0500381 explicit_output_format = false;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400382
Behdad Esfahbodf7e2ef72011-09-15 17:52:00 -0400383 fp = NULL;
384
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400385 add_options (parser);
386 }
Behdad Esfahbodf7e2ef72011-09-15 17:52:00 -0400387 ~output_options_t (void) {
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800388 g_free (output_file);
389 g_free (output_format);
Behdad Esfahbod55aeb042011-09-16 02:08:36 -0400390 if (fp)
Behdad Esfahbodf7e2ef72011-09-15 17:52:00 -0400391 fclose (fp);
392 }
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400393
394 void add_options (option_parser_t *parser);
395
396 void post_parse (GError **error G_GNUC_UNUSED)
397 {
Behdad Esfahbod6bad0922012-12-21 16:01:52 -0500398 if (output_format)
399 explicit_output_format = true;
400
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400401 if (output_file && !output_format) {
402 output_format = strrchr (output_file, '.');
403 if (output_format)
Behdad Esfahbode97835a2015-11-10 11:37:01 -0800404 {
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400405 output_format++; /* skip the dot */
Behdad Esfahbode97835a2015-11-10 11:37:01 -0800406 output_format = strdup (output_format);
407 }
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400408 }
409
Behdad Esfahbodf7e2ef72011-09-15 17:52:00 -0400410 if (output_file && 0 == strcmp (output_file, "-"))
411 output_file = NULL; /* STDOUT */
412 }
413
Behdad Esfahboda75c1b12011-09-16 01:16:41 -0400414 FILE *get_file_handle (void);
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400415
Behdad Esfahbod3530cc22015-11-03 11:34:47 -0800416 char *output_file;
417 char *output_format;
Behdad Esfahbodea5e8a02014-03-19 15:38:02 -0700418 const char **supported_formats;
Behdad Esfahbod6bad0922012-12-21 16:01:52 -0500419 bool explicit_output_format;
Behdad Esfahbodf7e2ef72011-09-15 17:52:00 -0400420
421 mutable FILE *fp;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -0400422};
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200423
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -0400424struct format_options_t : option_group_t
425{
426 format_options_t (option_parser_t *parser) {
427 show_glyph_names = true;
428 show_positions = true;
429 show_clusters = true;
Behdad Esfahbodcc4d9812012-01-19 12:32:20 -0500430 show_text = false;
431 show_unicode = false;
Behdad Esfahbodcdc673d2012-01-19 12:46:18 -0500432 show_line_num = false;
Behdad Esfahbodfdd17702015-08-24 13:49:55 +0100433 show_extents = false;
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -0400434
435 add_options (parser);
436 }
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -0400437
438 void add_options (option_parser_t *parser);
439
Behdad Esfahbodcdc673d2012-01-19 12:46:18 -0500440 void serialize_unicode (hb_buffer_t *buffer,
441 GString *gs);
442 void serialize_glyphs (hb_buffer_t *buffer,
443 hb_font_t *font,
Behdad Esfahbodf9edf162012-11-15 12:14:09 -0800444 hb_buffer_serialize_format_t format,
445 hb_buffer_serialize_flags_t flags,
Behdad Esfahbodcdc673d2012-01-19 12:46:18 -0500446 GString *gs);
447 void serialize_line_no (unsigned int line_no,
448 GString *gs);
Behdad Esfahbod5db06832012-06-02 12:13:08 -0400449 void serialize_buffer_of_text (hb_buffer_t *buffer,
450 unsigned int line_no,
451 const char *text,
452 unsigned int text_len,
453 hb_font_t *font,
Behdad Esfahbod5db06832012-06-02 12:13:08 -0400454 GString *gs);
455 void serialize_message (unsigned int line_no,
456 const char *msg,
457 GString *gs);
458 void serialize_buffer_of_glyphs (hb_buffer_t *buffer,
459 unsigned int line_no,
460 const char *text,
461 unsigned int text_len,
462 hb_font_t *font,
Behdad Esfahbodf9edf162012-11-15 12:14:09 -0800463 hb_buffer_serialize_format_t output_format,
464 hb_buffer_serialize_flags_t format_flags,
Behdad Esfahbod5db06832012-06-02 12:13:08 -0400465 GString *gs);
Behdad Esfahbodcdc673d2012-01-19 12:46:18 -0500466
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -0400467
Behdad Esfahbod088c1e22011-09-20 14:43:55 -0400468 hb_bool_t show_glyph_names;
469 hb_bool_t show_positions;
470 hb_bool_t show_clusters;
Behdad Esfahbodcc4d9812012-01-19 12:32:20 -0500471 hb_bool_t show_text;
472 hb_bool_t show_unicode;
Behdad Esfahbodcdc673d2012-01-19 12:46:18 -0500473 hb_bool_t show_line_num;
Behdad Esfahbodfdd17702015-08-24 13:49:55 +0100474 hb_bool_t show_extents;
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -0400475};
476
Chun-wei Fana49e7b72015-11-03 18:49:34 +0800477/* fallback implementation for scalbn()/scalbnf() for pre-2013 MSVC */
478#if defined (_MSC_VER) && (_MSC_VER < 1800)
479
480#ifndef FLT_RADIX
481#define FLT_RADIX 2
482#endif
483
484__inline long double scalbn (long double x, int exp)
485{
486 return x * (pow ((long double) FLT_RADIX, exp));
487}
488
489__inline float scalbnf (float x, int exp)
490{
491 return x * (pow ((float) FLT_RADIX, exp));
492}
493#endif
Behdad Esfahbod3bb300e2011-08-11 11:54:31 +0200494
495#endif