Behdad Esfahbod | c87b317 | 2012-05-15 23:53:18 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 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 | |
| 27 | #include "main-font-text.hh" |
| 28 | |
| 29 | #ifdef HAVE_FREETYPE |
| 30 | #include <hb-ft.h> |
| 31 | #endif |
| 32 | |
| 33 | struct shape_closure_consumer_t : option_group_t |
| 34 | { |
| 35 | shape_closure_consumer_t (option_parser_t *parser) : |
| 36 | shaper (parser), |
| 37 | show_glyph_names (true) |
| 38 | { |
| 39 | add_options (parser); |
| 40 | } |
| 41 | |
| 42 | void add_options (struct option_parser_t *parser) |
| 43 | { |
| 44 | GOptionEntry entries[] = |
| 45 | { |
| 46 | {"no-glyph-names", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &this->show_glyph_names, "Use glyph indices instead of names", NULL}, |
| 47 | {NULL} |
| 48 | }; |
| 49 | parser->add_group (entries, |
| 50 | "format", |
| 51 | "Format options:", |
| 52 | "Options controlling output formatting", |
| 53 | this); |
| 54 | } |
| 55 | |
| 56 | void init (const font_options_t *font_opts) |
| 57 | { |
| 58 | glyphs = hb_set_create (); |
| 59 | font = hb_font_reference (font_opts->get_font ()); |
Behdad Esfahbod | 5db0683 | 2012-06-02 12:13:08 -0400 | [diff] [blame] | 60 | failed = false; |
Behdad Esfahbod | c87b317 | 2012-05-15 23:53:18 -0400 | [diff] [blame] | 61 | } |
| 62 | void consume_line (hb_buffer_t *buffer, |
| 63 | const char *text, |
Behdad Esfahbod | 321f73c | 2012-11-13 15:12:24 -0800 | [diff] [blame] | 64 | unsigned int text_len, |
| 65 | const char *text_before, |
| 66 | const char *text_after) |
Behdad Esfahbod | c87b317 | 2012-05-15 23:53:18 -0400 | [diff] [blame] | 67 | { |
Behdad Esfahbod | c87b317 | 2012-05-15 23:53:18 -0400 | [diff] [blame] | 68 | hb_set_clear (glyphs); |
| 69 | shaper.shape_closure (text, text_len, font, buffer, glyphs); |
Behdad Esfahbod | 29ce446 | 2012-05-25 14:17:54 -0400 | [diff] [blame] | 70 | |
Behdad Esfahbod | aec89de | 2012-11-15 16:15:42 -0800 | [diff] [blame] | 71 | if (hb_set_is_empty (glyphs)) |
Behdad Esfahbod | 29ce446 | 2012-05-25 14:17:54 -0400 | [diff] [blame] | 72 | return; |
| 73 | |
Behdad Esfahbod | c87b317 | 2012-05-15 23:53:18 -0400 | [diff] [blame] | 74 | /* Print it out! */ |
Behdad Esfahbod | c87b317 | 2012-05-15 23:53:18 -0400 | [diff] [blame] | 75 | bool first = true; |
Behdad Esfahbod | 29ce446 | 2012-05-25 14:17:54 -0400 | [diff] [blame] | 76 | for (hb_codepoint_t i = -1; hb_set_next (glyphs, &i);) |
Behdad Esfahbod | 75da37d | 2012-11-15 18:39:23 -0800 | [diff] [blame] | 77 | { |
| 78 | if (first) |
| 79 | first = false; |
| 80 | else |
| 81 | printf (" "); |
Behdad Esfahbod | 7235f33 | 2013-06-10 14:39:51 -0400 | [diff] [blame] | 82 | if (show_glyph_names) |
| 83 | { |
| 84 | char glyph_name[64]; |
Behdad Esfahbod | 5fbc952 | 2013-07-29 14:34:40 -0400 | [diff] [blame] | 85 | hb_font_glyph_to_string (font, i, glyph_name, sizeof (glyph_name)); |
Behdad Esfahbod | 75da37d | 2012-11-15 18:39:23 -0800 | [diff] [blame] | 86 | printf ("%s", glyph_name); |
| 87 | } else |
| 88 | printf ("%u", i); |
| 89 | } |
Behdad Esfahbod | c87b317 | 2012-05-15 23:53:18 -0400 | [diff] [blame] | 90 | } |
| 91 | void finish (const font_options_t *font_opts) |
| 92 | { |
| 93 | printf ("\n"); |
| 94 | hb_font_destroy (font); |
| 95 | font = NULL; |
| 96 | hb_set_destroy (glyphs); |
| 97 | glyphs = NULL; |
| 98 | } |
| 99 | |
Behdad Esfahbod | 5db0683 | 2012-06-02 12:13:08 -0400 | [diff] [blame] | 100 | bool failed; |
| 101 | |
Behdad Esfahbod | c87b317 | 2012-05-15 23:53:18 -0400 | [diff] [blame] | 102 | protected: |
| 103 | shape_options_t shaper; |
| 104 | hb_bool_t show_glyph_names; |
| 105 | |
| 106 | hb_set_t *glyphs; |
| 107 | hb_font_t *font; |
| 108 | }; |
| 109 | |
| 110 | int |
| 111 | main (int argc, char **argv) |
| 112 | { |
Behdad Esfahbod | cd4eb96 | 2015-01-20 12:30:45 -0800 | [diff] [blame] | 113 | main_font_text_t<shape_closure_consumer_t, FONT_SIZE_NONE, 0> driver; |
Behdad Esfahbod | c87b317 | 2012-05-15 23:53:18 -0400 | [diff] [blame] | 114 | return driver.main (argc, argv); |
| 115 | } |