blob: 8ee4bd697fdbfccdbb3d80044c15386f0cd9a55a [file] [log] [blame]
Behdad Esfahbod45675e52012-05-15 23:10:39 -04001/*
2 * Copyright © 2011,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
Behdad Esfahbod45675e52012-05-15 23:10:39 -040027#ifndef HB_SHAPE_CONSUMER_HH
28#define HB_SHAPE_CONSUMER_HH
29
Behdad Esfahbod58c22332021-08-06 23:45:59 -060030#include "font-options.hh"
Behdad Esfahbodc3599fd2021-08-06 23:24:28 -060031#include "shape-options.hh"
Behdad Esfahbod97a9e4e2021-08-11 19:28:16 -060032#include "text-options.hh"
Behdad Esfahbod17f40b72017-10-27 09:22:30 -060033
Behdad Esfahbod45675e52012-05-15 23:10:39 -040034
35template <typename output_t>
Behdad Esfahbod4e976782021-08-06 22:53:44 -060036struct shape_consumer_t : shape_options_t
Behdad Esfahbod45675e52012-05-15 23:10:39 -040037{
Behdad Esfahbode109f9a2021-08-05 11:05:51 -060038 void add_options (option_parser_t *parser)
39 {
Behdad Esfahbod4e976782021-08-06 22:53:44 -060040 shape_options_t::add_options (parser);
Behdad Esfahbode109f9a2021-08-05 11:05:51 -060041 output.add_options (parser);
42 }
Behdad Esfahbod45675e52012-05-15 23:10:39 -040043
Behdad Esfahbodda285d52021-09-14 08:28:12 -040044 template <typename app_t>
45 void init (const app_t *app)
Behdad Esfahbod45675e52012-05-15 23:10:39 -040046 {
Behdad Esfahbod5db06832012-06-02 12:13:08 -040047 failed = false;
Behdad Esfahbodfc0339e2021-08-05 13:35:46 -060048 buffer = hb_buffer_create ();
Behdad Esfahbode6035052017-07-18 19:14:19 -070049
Behdad Esfahbodda285d52021-09-14 08:28:12 -040050 output.init (buffer, app);
Behdad Esfahbod45675e52012-05-15 23:10:39 -040051 }
Behdad Esfahbodda285d52021-09-14 08:28:12 -040052 template <typename app_t>
53 bool consume_line (app_t &app)
Behdad Esfahbod45675e52012-05-15 23:10:39 -040054 {
Behdad Esfahbod97a9e4e2021-08-11 19:28:16 -060055 unsigned int text_len;
56 const char *text;
Behdad Esfahbodda285d52021-09-14 08:28:12 -040057 if (!(text = app.get_line (&text_len)))
Behdad Esfahbod97a9e4e2021-08-11 19:28:16 -060058 return false;
59
Behdad Esfahbod5db06832012-06-02 12:13:08 -040060 output.new_line ();
Behdad Esfahbodae621662012-06-02 12:21:19 -040061
Behdad Esfahbod4e976782021-08-06 22:53:44 -060062 for (unsigned int n = num_iterations; n; n--)
Behdad Esfahbod50067e22013-04-11 16:31:01 -040063 {
Behdad Esfahbodda285d52021-09-14 08:28:12 -040064 populate_buffer (buffer, text, text_len, app.text_before, app.text_after);
Behdad Esfahbode4046082013-04-17 23:49:54 -040065 if (n == 1)
Behdad Esfahbod4e976782021-08-06 22:53:44 -060066 output.consume_text (buffer, text, text_len, utf8_clusters);
Seigo Nonakac62d6f42023-03-01 19:52:57 +090067
68 const char *error = nullptr;
Behdad Esfahbodda285d52021-09-14 08:28:12 -040069 if (!shape (app.font, buffer, &error))
Behdad Esfahbode6035052017-07-18 19:14:19 -070070 {
Behdad Esfahbod50067e22013-04-11 16:31:01 -040071 failed = true;
Behdad Esfahbodd2052272017-08-11 15:12:25 -070072 output.error (error);
73 if (hb_buffer_get_content_type (buffer) == HB_BUFFER_CONTENT_TYPE_GLYPHS)
74 break;
75 else
Behdad Esfahbod97a9e4e2021-08-11 19:28:16 -060076 return true;
Behdad Esfahbod50067e22013-04-11 16:31:01 -040077 }
Behdad Esfahbod5db06832012-06-02 12:13:08 -040078 }
79
Behdad Esfahbod4e976782021-08-06 22:53:44 -060080 output.consume_glyphs (buffer, text, text_len, utf8_clusters);
Behdad Esfahbod97a9e4e2021-08-11 19:28:16 -060081 return true;
Behdad Esfahbod45675e52012-05-15 23:10:39 -040082 }
Behdad Esfahbodda285d52021-09-14 08:28:12 -040083 template <typename app_t>
84 void finish (const app_t *app)
Behdad Esfahbod45675e52012-05-15 23:10:39 -040085 {
Behdad Esfahbodda285d52021-09-14 08:28:12 -040086 output.finish (buffer, app);
Behdad Esfahbode6035052017-07-18 19:14:19 -070087 hb_buffer_destroy (buffer);
Behdad Esfahboddbdbfe32017-10-15 12:11:08 +020088 buffer = nullptr;
Behdad Esfahbod45675e52012-05-15 23:10:39 -040089 }
90
Behdad Esfahbod5db06832012-06-02 12:13:08 -040091 public:
Behdad Esfahbode57dd662021-08-05 10:33:31 -060092 bool failed = false;
Behdad Esfahbod5db06832012-06-02 12:13:08 -040093
Behdad Esfahbod45675e52012-05-15 23:10:39 -040094 protected:
Behdad Esfahbod45675e52012-05-15 23:10:39 -040095 output_t output;
96
Behdad Esfahbode57dd662021-08-05 10:33:31 -060097 hb_buffer_t *buffer = nullptr;
Behdad Esfahbod45675e52012-05-15 23:10:39 -040098};
99
100
101#endif