blob: 00df68c293023853258caa00549c22f4cf351a79 [file] [log] [blame]
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -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
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040027#ifndef VIEW_CAIRO_HH
28#define VIEW_CAIRO_HH
29
Behdad Esfahbod17f40b72017-10-27 09:22:30 -060030#include "hb-private.hh"
31#include "options.hh"
32#include "helper-cairo.hh"
33
Behdad Esfahbod8b8b1902011-09-19 16:41:17 -040034
Behdad Esfahbod7235f332013-06-10 14:39:51 -040035struct view_cairo_t
36{
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040037 view_cairo_t (option_parser_t *parser)
Behdad Esfahbod9815a882012-12-21 16:46:53 -050038 : output_options (parser, helper_cairo_supported_formats),
Behdad Esfahbod7235f332013-06-10 14:39:51 -040039 view_options (parser),
Behdad Esfahbodadb03952013-12-04 20:10:02 -050040 direction (HB_DIRECTION_INVALID),
Behdad Esfahbodcd4eb962015-01-20 12:30:45 -080041 lines (0), scale_bits (0) {}
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040042 ~view_cairo_t (void) {
Ebrahim Byagowice173402018-04-20 10:29:06 +043043 cairo_debug_reset_static_data ();
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040044 }
45
Behdad Esfahbode6035052017-07-18 19:14:19 -070046 void init (hb_buffer_t *buffer, const font_options_t *font_opts)
Behdad Esfahbod5db06832012-06-02 12:13:08 -040047 {
Behdad Esfahbod0594a242012-06-05 20:35:40 -040048 lines = g_array_new (false, false, sizeof (helper_cairo_line_t));
Behdad Esfahbodcd4eb962015-01-20 12:30:45 -080049 scale_bits = -font_opts->subpixel_bits;
Behdad Esfahbod5db06832012-06-02 12:13:08 -040050 }
51 void new_line (void)
52 {
53 }
54 void consume_text (hb_buffer_t *buffer,
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040055 const char *text,
Behdad Esfahbod95cefdf2012-04-16 18:08:20 -040056 unsigned int text_len,
Behdad Esfahbod5db06832012-06-02 12:13:08 -040057 hb_bool_t utf8_clusters)
58 {
59 }
Behdad Esfahbodd2052272017-08-11 15:12:25 -070060 void error (const char *message)
Behdad Esfahbod5db06832012-06-02 12:13:08 -040061 {
Behdad Esfahbod69d701b2017-08-30 17:07:29 -070062 g_printerr ("%s: %s\n", g_get_prgname (), message);
Behdad Esfahbod5db06832012-06-02 12:13:08 -040063 }
64 void consume_glyphs (hb_buffer_t *buffer,
65 const char *text,
66 unsigned int text_len,
67 hb_bool_t utf8_clusters)
68 {
69 direction = hb_buffer_get_direction (buffer);
70 helper_cairo_line_t l;
Behdad Esfahbodcd4eb962015-01-20 12:30:45 -080071 helper_cairo_line_from_buffer (&l, buffer, text, text_len, scale_bits, utf8_clusters);
Behdad Esfahbod5db06832012-06-02 12:13:08 -040072 g_array_append_val (lines, l);
73 }
Behdad Esfahbode6035052017-07-18 19:14:19 -070074 void finish (hb_buffer_t *buffer, const font_options_t *font_opts)
Behdad Esfahbod5db06832012-06-02 12:13:08 -040075 {
76 render (font_opts);
77
78 for (unsigned int i = 0; i < lines->len; i++) {
79 helper_cairo_line_t &line = g_array_index (lines, helper_cairo_line_t, i);
80 line.finish ();
81 }
Behdad Esfahbodc2bc8182013-10-27 23:36:35 +010082#if GLIB_CHECK_VERSION (2, 22, 0)
83 g_array_unref (lines);
84#else
Behdad Esfahbod078de492013-09-26 18:26:43 -040085 g_array_free (lines, TRUE);
Behdad Esfahbodc2bc8182013-10-27 23:36:35 +010086#endif
Behdad Esfahbod5db06832012-06-02 12:13:08 -040087 }
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040088
89 protected:
90
Behdad Esfahbod5db06832012-06-02 12:13:08 -040091 output_options_t output_options;
92 view_options_t view_options;
93
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040094 void render (const font_options_t *font_opts);
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040095
Behdad Esfahbod69b84a82012-04-12 15:50:40 -040096 hb_direction_t direction; // Remove this, make segment_properties accessible
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040097 GArray *lines;
Behdad Esfahbodcd4eb962015-01-20 12:30:45 -080098 int scale_bits;
Behdad Esfahbodb9b10ad2011-09-13 13:30:39 -040099};
100
101#endif