Behdad Esfahbod | b9b10ad | 2011-09-13 13:30:39 -0400 | [diff] [blame] | 1 | /* |
| 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 Esfahbod | b9b10ad | 2011-09-13 13:30:39 -0400 | [diff] [blame] | 27 | #ifndef VIEW_CAIRO_HH |
| 28 | #define VIEW_CAIRO_HH |
| 29 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 30 | #include "hb.hh" |
Behdad Esfahbod | 17f40b7 | 2017-10-27 09:22:30 -0600 | [diff] [blame] | 31 | #include "options.hh" |
| 32 | #include "helper-cairo.hh" |
| 33 | |
Behdad Esfahbod | 8b8b190 | 2011-09-19 16:41:17 -0400 | [diff] [blame] | 34 | |
Behdad Esfahbod | 7235f33 | 2013-06-10 14:39:51 -0400 | [diff] [blame] | 35 | struct view_cairo_t |
| 36 | { |
Behdad Esfahbod | b9b10ad | 2011-09-13 13:30:39 -0400 | [diff] [blame] | 37 | view_cairo_t (option_parser_t *parser) |
Behdad Esfahbod | 9815a88 | 2012-12-21 16:46:53 -0500 | [diff] [blame] | 38 | : output_options (parser, helper_cairo_supported_formats), |
Behdad Esfahbod | 7235f33 | 2013-06-10 14:39:51 -0400 | [diff] [blame] | 39 | view_options (parser), |
Behdad Esfahbod | adb0395 | 2013-12-04 20:10:02 -0500 | [diff] [blame] | 40 | direction (HB_DIRECTION_INVALID), |
Behdad Esfahbod | cd4eb96 | 2015-01-20 12:30:45 -0800 | [diff] [blame] | 41 | lines (0), scale_bits (0) {} |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 42 | ~view_cairo_t () { |
Ebrahim Byagowi | ce17340 | 2018-04-20 10:29:06 +0430 | [diff] [blame] | 43 | cairo_debug_reset_static_data (); |
Behdad Esfahbod | b9b10ad | 2011-09-13 13:30:39 -0400 | [diff] [blame] | 44 | } |
| 45 | |
Behdad Esfahbod | e603505 | 2017-07-18 19:14:19 -0700 | [diff] [blame] | 46 | void init (hb_buffer_t *buffer, const font_options_t *font_opts) |
Behdad Esfahbod | 5db0683 | 2012-06-02 12:13:08 -0400 | [diff] [blame] | 47 | { |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 48 | lines = g_array_new (false, false, sizeof (helper_cairo_line_t)); |
Behdad Esfahbod | 310bdac | 2018-10-04 16:31:14 +0200 | [diff] [blame] | 49 | scale_bits = - (int) font_opts->subpixel_bits; |
Behdad Esfahbod | 5db0683 | 2012-06-02 12:13:08 -0400 | [diff] [blame] | 50 | } |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 51 | void new_line () {} |
Behdad Esfahbod | 5db0683 | 2012-06-02 12:13:08 -0400 | [diff] [blame] | 52 | void consume_text (hb_buffer_t *buffer, |
Behdad Esfahbod | b9b10ad | 2011-09-13 13:30:39 -0400 | [diff] [blame] | 53 | const char *text, |
Behdad Esfahbod | 95cefdf | 2012-04-16 18:08:20 -0400 | [diff] [blame] | 54 | unsigned int text_len, |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 55 | hb_bool_t utf8_clusters) {} |
Behdad Esfahbod | d205227 | 2017-08-11 15:12:25 -0700 | [diff] [blame] | 56 | void error (const char *message) |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 57 | { g_printerr ("%s: %s\n", g_get_prgname (), message); } |
Behdad Esfahbod | 5db0683 | 2012-06-02 12:13:08 -0400 | [diff] [blame] | 58 | void consume_glyphs (hb_buffer_t *buffer, |
| 59 | const char *text, |
| 60 | unsigned int text_len, |
| 61 | hb_bool_t utf8_clusters) |
| 62 | { |
| 63 | direction = hb_buffer_get_direction (buffer); |
| 64 | helper_cairo_line_t l; |
Behdad Esfahbod | cd4eb96 | 2015-01-20 12:30:45 -0800 | [diff] [blame] | 65 | helper_cairo_line_from_buffer (&l, buffer, text, text_len, scale_bits, utf8_clusters); |
Behdad Esfahbod | 5db0683 | 2012-06-02 12:13:08 -0400 | [diff] [blame] | 66 | g_array_append_val (lines, l); |
| 67 | } |
Behdad Esfahbod | e603505 | 2017-07-18 19:14:19 -0700 | [diff] [blame] | 68 | void finish (hb_buffer_t *buffer, const font_options_t *font_opts) |
Behdad Esfahbod | 5db0683 | 2012-06-02 12:13:08 -0400 | [diff] [blame] | 69 | { |
| 70 | render (font_opts); |
| 71 | |
| 72 | for (unsigned int i = 0; i < lines->len; i++) { |
| 73 | helper_cairo_line_t &line = g_array_index (lines, helper_cairo_line_t, i); |
| 74 | line.finish (); |
| 75 | } |
Behdad Esfahbod | c2bc818 | 2013-10-27 23:36:35 +0100 | [diff] [blame] | 76 | #if GLIB_CHECK_VERSION (2, 22, 0) |
| 77 | g_array_unref (lines); |
| 78 | #else |
Behdad Esfahbod | 078de49 | 2013-09-26 18:26:43 -0400 | [diff] [blame] | 79 | g_array_free (lines, TRUE); |
Behdad Esfahbod | c2bc818 | 2013-10-27 23:36:35 +0100 | [diff] [blame] | 80 | #endif |
Behdad Esfahbod | 5db0683 | 2012-06-02 12:13:08 -0400 | [diff] [blame] | 81 | } |
Behdad Esfahbod | b9b10ad | 2011-09-13 13:30:39 -0400 | [diff] [blame] | 82 | |
| 83 | protected: |
| 84 | |
Behdad Esfahbod | 5db0683 | 2012-06-02 12:13:08 -0400 | [diff] [blame] | 85 | output_options_t output_options; |
| 86 | view_options_t view_options; |
| 87 | |
Behdad Esfahbod | b9b10ad | 2011-09-13 13:30:39 -0400 | [diff] [blame] | 88 | void render (const font_options_t *font_opts); |
Behdad Esfahbod | b9b10ad | 2011-09-13 13:30:39 -0400 | [diff] [blame] | 89 | |
Behdad Esfahbod | 69b84a8 | 2012-04-12 15:50:40 -0400 | [diff] [blame] | 90 | hb_direction_t direction; // Remove this, make segment_properties accessible |
Behdad Esfahbod | b9b10ad | 2011-09-13 13:30:39 -0400 | [diff] [blame] | 91 | GArray *lines; |
Behdad Esfahbod | cd4eb96 | 2015-01-20 12:30:45 -0800 | [diff] [blame] | 92 | int scale_bits; |
Behdad Esfahbod | b9b10ad | 2011-09-13 13:30:39 -0400 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | #endif |