blob: 1799ccad334f54204db08b776782c4f5e6462aea [file] [log] [blame]
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -04001/*
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
27#include "common.hh"
28#include "options.hh"
29
30#ifndef HB_VIEW_HH
31#define HB_VIEW_HH
32
33template <typename output_t>
34struct hb_view_t
35{
36 static int
37 main (int argc, char **argv)
38 {
39 option_parser_t options ("[FONT-FILE] [TEXT]");
40
41 shape_options_t shaper (&options);
42 font_options_t font_opts (&options);
43 text_options_t input (&options);
44
45 output_t output (&options);
46
47 options.parse (&argc, &argv);
48
49 argc--, argv++;
50 if (argc && !font_opts.font_file) font_opts.font_file = argv[0], argc--, argv++;
51 if (argc && !input.text && !input.text_file) input.text = argv[0], argc--, argv++;
52 if (argc)
53 fail (TRUE, "Too many arguments on the command line");
54 if (!font_opts.font_file || (!input.text && !input.text_file))
55 options.usage ();
56
57 output.init (&font_opts);
58
59 hb_buffer_t *buffer = hb_buffer_create ();
60 unsigned int text_len;
61 const char *text;
62 while ((text = input.get_line (&text_len)))
63 {
64 if (!shaper.shape (text, text_len,
65 font_opts.get_font (),
66 buffer))
67 fail (FALSE, "All shapers failed");
68
69 output.consume_line (buffer, text, text_len);
70 }
71 hb_buffer_destroy (buffer);
72
73 output.finish (&font_opts);
74
75 return 0;
76 }
77};
78
79#endif