options.hh revision 111f3e55178f7cd5a8ae4e8ae111cb48aea4acb5
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_, 288111f3e55178f7cd5a8ae4e8ae111cb48aea4acb5Behdad Esfahbod unsigned int subpixel_bits_) 289111f3e55178f7cd5a8ae4e8ae111cb48aea4acb5Behdad Esfahbod { 290111f3e55178f7cd5a8ae4e8ae111cb48aea4acb5Behdad Esfahbod variations = NULL; 291111f3e55178f7cd5a8ae4e8ae111cb48aea4acb5Behdad Esfahbod num_variations = 0; 292cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod default_font_size = default_font_size_; 293cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod subpixel_bits = subpixel_bits_; 294b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod font_file = NULL; 295b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod face_index = 0; 296cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod font_size_x = font_size_y = default_font_size; 2978650def73500204b79c651f58b1be3f94a41973dBehdad Esfahbod font_funcs = NULL; 298b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 299b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod font = NULL; 300b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 301b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod add_options (parser); 302b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod } 303b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod ~font_options_t (void) { 3043530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod g_free (font_file); 305111f3e55178f7cd5a8ae4e8ae111cb48aea4acb5Behdad Esfahbod free (variations); 3063530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod g_free (font_funcs); 307b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod hb_font_destroy (font); 3083bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod } 3093bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 310b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod void add_options (option_parser_t *parser); 311b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 312b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod hb_font_t *get_font (void) const; 313bc4b07b05ea9e39eb9f966eb2c3e1c737efa77ffBehdad Esfahbod 3143530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod char *font_file; 3153bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod int face_index; 316111f3e55178f7cd5a8ae4e8ae111cb48aea4acb5Behdad Esfahbod hb_variation_t *variations; 317111f3e55178f7cd5a8ae4e8ae111cb48aea4acb5Behdad Esfahbod unsigned int num_variations; 318cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod int default_font_size; 319cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod unsigned int subpixel_bits; 320cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod mutable double font_size_x; 321cd4eb96abb90a84b42e9b288e39bad759e4411a0Behdad Esfahbod mutable double font_size_y; 3223530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod char *font_funcs; 3233bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 324b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod private: 325b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod mutable hb_font_t *font; 326b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod}; 327b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 328b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 329b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstruct text_options_t : option_group_t 330b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 331b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod text_options_t (option_parser_t *parser) { 332321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod text_before = NULL; 333321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod text_after = NULL; 334321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod 335b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod text = NULL; 336b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod text_file = NULL; 337b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 33855aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod fp = NULL; 33955aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod gs = NULL; 3403530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod line = NULL; 3413530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod line_len = (unsigned int) -1; 342b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 343b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod add_options (parser); 344b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod } 345b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod ~text_options_t (void) { 3463530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod g_free (text_before); 3473530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod g_free (text_after); 3483530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod g_free (text); 3493530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod g_free (text_file); 35055aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (gs) 3510594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod g_string_free (gs, true); 35255aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (fp) 35355aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod fclose (fp); 354b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod } 355b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 356b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod void add_options (option_parser_t *parser); 357b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 358b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod void post_parse (GError **error G_GNUC_UNUSED) { 359b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod if (text && text_file) 360b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod g_set_error (error, 361b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, 36230874b4819a99cc84fa39e794266685e1b8735d2Behdad Esfahbod "Only one of text and text-file can be set"); 363b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod }; 364b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 365b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod const char *get_line (unsigned int *len); 366b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 3673530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod char *text_before; 3683530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod char *text_after; 369321f73c16efa0730c96e001d65268f4927a0f735Behdad Esfahbod 3703530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod char *text; 3713530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod char *text_file; 372b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 373b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod private: 37455aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod FILE *fp; 37555aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod GString *gs; 3763530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod char *line; 3773530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod unsigned int line_len; 378b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod}; 379b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 380b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbodstruct output_options_t : option_group_t 381b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod{ 3829815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod output_options_t (option_parser_t *parser, 383ea5e8a02eb83ad19f3009b0008893f77ce113118Behdad Esfahbod const char **supported_formats_ = NULL) { 384b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod output_file = NULL; 385b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod output_format = NULL; 3869815a88111072aa51e78e258c5f660993b47d4dfBehdad Esfahbod supported_formats = supported_formats_; 3876bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2Behdad Esfahbod explicit_output_format = false; 388b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 389f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod fp = NULL; 390f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod 391b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod add_options (parser); 392b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod } 393f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod ~output_options_t (void) { 3943530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod g_free (output_file); 3953530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod g_free (output_format); 39655aeb0490454cc1ba93a42f307ed1230f59dee4bBehdad Esfahbod if (fp) 397f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod fclose (fp); 398f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod } 399b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 400b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod void add_options (option_parser_t *parser); 401b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 402b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod void post_parse (GError **error G_GNUC_UNUSED) 403b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod { 4046bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2Behdad Esfahbod if (output_format) 4056bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2Behdad Esfahbod explicit_output_format = true; 4066bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2Behdad Esfahbod 407b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod if (output_file && !output_format) { 408b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod output_format = strrchr (output_file, '.'); 409b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod if (output_format) 410e97835ad43f5c68e8cb29599246cae0f4461d663Behdad Esfahbod { 411b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod output_format++; /* skip the dot */ 412e97835ad43f5c68e8cb29599246cae0f4461d663Behdad Esfahbod output_format = strdup (output_format); 413e97835ad43f5c68e8cb29599246cae0f4461d663Behdad Esfahbod } 414b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod } 415b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod 416f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod if (output_file && 0 == strcmp (output_file, "-")) 417f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod output_file = NULL; /* STDOUT */ 418f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod } 419f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod 420a75c1b125159f6cfb6b652a9ec40803f7c7e3f71Behdad Esfahbod FILE *get_file_handle (void); 4213bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 4223530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod char *output_file; 4233530cc2d7c3b7102902cb0e38b0bf9f46188078dBehdad Esfahbod char *output_format; 424ea5e8a02eb83ad19f3009b0008893f77ce113118Behdad Esfahbod const char **supported_formats; 4256bad092aa87bc3e6bbf0b9faf07693e6ebbe55f2Behdad Esfahbod bool explicit_output_format; 426f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod 427f7e2ef74f856ee13d6fd6cf3f1e04bc162203bc2Behdad Esfahbod mutable FILE *fp; 428b9b10ad78b1f977494a3a42b58f8040fe16505a3Behdad Esfahbod}; 4293bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 4308b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbodstruct format_options_t : option_group_t 4318b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod{ 4328b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod format_options_t (option_parser_t *parser) { 4338b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod show_glyph_names = true; 4348b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod show_positions = true; 4358b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod show_clusters = true; 436cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod show_text = false; 437cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod show_unicode = false; 438cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod show_line_num = false; 439fdd1770e006ca2d2973c049177ceda87a575e07fBehdad Esfahbod show_extents = false; 4408b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 4418b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod add_options (parser); 4428b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod } 4438b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 4448b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod void add_options (option_parser_t *parser); 4458b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 446cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod void serialize_unicode (hb_buffer_t *buffer, 447cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod GString *gs); 448cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod void serialize_glyphs (hb_buffer_t *buffer, 449cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod hb_font_t *font, 450f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod hb_buffer_serialize_format_t format, 451f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod hb_buffer_serialize_flags_t flags, 452cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod GString *gs); 453cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod void serialize_line_no (unsigned int line_no, 454cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod GString *gs); 4555db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod void serialize_buffer_of_text (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, 4605db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod GString *gs); 4615db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod void serialize_message (unsigned int line_no, 4625db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod const char *msg, 4635db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod GString *gs); 4645db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod void serialize_buffer_of_glyphs (hb_buffer_t *buffer, 4655db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod unsigned int line_no, 4665db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod const char *text, 4675db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod unsigned int text_len, 4685db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod hb_font_t *font, 469f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod hb_buffer_serialize_format_t output_format, 470f9edf1672511c3bcc3796cc79578ffea43b2bda1Behdad Esfahbod hb_buffer_serialize_flags_t format_flags, 4715db0683a822f70c914468430cda6487cee740ae3Behdad Esfahbod GString *gs); 472cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod 4738b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 474088c1e27c0fc0cdef999cf1f567e4d5eb2cfb2e4Behdad Esfahbod hb_bool_t show_glyph_names; 475088c1e27c0fc0cdef999cf1f567e4d5eb2cfb2e4Behdad Esfahbod hb_bool_t show_positions; 476088c1e27c0fc0cdef999cf1f567e4d5eb2cfb2e4Behdad Esfahbod hb_bool_t show_clusters; 477cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod hb_bool_t show_text; 478cc4d9810d6318ca2e4de3b8d62f03b51cc21ee05Behdad Esfahbod hb_bool_t show_unicode; 479cdc673d97c5ffedb386865a81f54a5cedcbad27cBehdad Esfahbod hb_bool_t show_line_num; 480fdd1770e006ca2d2973c049177ceda87a575e07fBehdad Esfahbod hb_bool_t show_extents; 4818b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod}; 4828b8b19056decaf09e4e0ccd9412ee1aeb30f4de7Behdad Esfahbod 483a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan/* fallback implementation for scalbn()/scalbnf() for pre-2013 MSVC */ 484a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan#if defined (_MSC_VER) && (_MSC_VER < 1800) 485a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan 486a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan#ifndef FLT_RADIX 487a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan#define FLT_RADIX 2 488a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan#endif 489a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan 490a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan__inline long double scalbn (long double x, int exp) 491a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan{ 492a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan return x * (pow ((long double) FLT_RADIX, exp)); 493a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan} 494a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan 495a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan__inline float scalbnf (float x, int exp) 496a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan{ 497a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan return x * (pow ((float) FLT_RADIX, exp)); 498a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan} 499a49e7b7e40127beba25f39ef3c10d7a77e2bb0f0Chun-wei Fan#endif 5003bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod 5013bb300ee78a40f9ded21ab19283863b733aeb677Behdad Esfahbod#endif 502