hb-shape.cc revision 95cefdf96efe43a44133aa8a186155cf4e63e2b7
1/*
2 * Copyright © 2010  Behdad Esfahbod
3 * Copyright © 2011  Google, Inc.
4 *
5 *  This is part of HarfBuzz, a text shaping library.
6 *
7 * Permission is hereby granted, without written agreement and without
8 * license or royalty fees, to use, copy, modify, and distribute this
9 * software and its documentation for any purpose, provided that the
10 * above copyright notice and the following two paragraphs appear in
11 * all copies of this software.
12 *
13 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
14 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
15 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
16 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
17 * DAMAGE.
18 *
19 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
20 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
22 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
23 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
24 *
25 * Google Author(s): Behdad Esfahbod
26 */
27
28#include "hb-view.hh"
29
30struct output_buffer_t : output_options_t, format_options_t
31{
32  output_buffer_t (option_parser_t *parser)
33		  : output_options_t (parser),
34		    format_options_t (parser) {}
35
36  void init (const font_options_t *font_opts);
37  void consume_line (hb_buffer_t  *buffer,
38		     const char   *text,
39		     unsigned int  text_len,
40		     hb_bool_t     utf8_clusters);
41  void finish (const font_options_t *font_opts);
42
43  protected:
44  GString *gs;
45  hb_font_t *font;
46  unsigned int line_no;
47};
48
49void
50output_buffer_t::init (const font_options_t *font_opts)
51{
52  get_file_handle ();
53  font = hb_font_reference (font_opts->get_font ());
54  gs = g_string_new (NULL);
55  line_no = 0;
56}
57
58void
59output_buffer_t::consume_line (hb_buffer_t  *buffer,
60			       const char   *text,
61			       unsigned int  text_len,
62			       hb_bool_t     utf8_clusters)
63{
64  line_no++;
65  g_string_set_size (gs, 0);
66  serialize_line (buffer, line_no, text, text_len, font, utf8_clusters, gs);
67  fprintf (fp, "%s", gs->str);
68}
69
70void
71output_buffer_t::finish (const font_options_t *font_opts)
72{
73  g_string_free (gs, TRUE);
74  gs = NULL;
75  hb_font_destroy (font);
76  font = NULL;
77}
78
79int
80main (int argc, char **argv)
81{
82  return hb_view_t<output_buffer_t>::main (argc, argv);
83}
84