blob: f3f3ab0c3e13ac7fa794aa148274f924389fd079 [file] [log] [blame]
Behdad Esfahboda2a9a022008-01-15 22:46:32 +00001/*
Behdad Esfahbod2409d5f2011-04-21 17:14:28 -04002 * Copyright © 1998-2004 David Turner and Werner Lemberg
3 * Copyright © 2004,2007,2009,2010 Red Hat, Inc.
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -04004 * Copyright © 2011 Google, Inc.
Behdad Esfahbod6b347132007-10-11 08:30:50 +00005 *
Behdad Esfahbod8f0d7e02011-04-15 18:59:56 -04006 * This is part of HarfBuzz, a text shaping library.
Behdad Esfahbod6b347132007-10-11 08:30:50 +00007 *
Behdad Esfahboda2a9a022008-01-15 22:46:32 +00008 * Permission is hereby granted, without written agreement and without
9 * license or royalty fees, to use, copy, modify, and distribute this
10 * software and its documentation for any purpose, provided that the
11 * above copyright notice and the following two paragraphs appear in
12 * all copies of this software.
Behdad Esfahbod6b347132007-10-11 08:30:50 +000013 *
Behdad Esfahboda2a9a022008-01-15 22:46:32 +000014 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
15 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
16 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
17 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
18 * DAMAGE.
19 *
20 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
21 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
22 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
23 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
24 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
25 *
26 * Red Hat Author(s): Owen Taylor, Behdad Esfahbod
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -040027 * Google Author(s): Behdad Esfahbod
Behdad Esfahbod6b347132007-10-11 08:30:50 +000028 */
Behdad Esfahboda2a9a022008-01-15 22:46:32 +000029
Behdad Esfahbodda8edbb2010-06-09 07:15:39 -040030#ifndef HB_BUFFER_PRIVATE_HH
31#define HB_BUFFER_PRIVATE_HH
Behdad Esfahbod6b347132007-10-11 08:30:50 +000032
Behdad Esfahbodc57d4542011-04-20 18:50:27 -040033#include "hb-private.hh"
Behdad Esfahbod5c0adce2009-05-20 05:42:12 -040034#include "hb-buffer.h"
Behdad Esfahbodfca368c2011-04-21 18:24:02 -040035#include "hb-object-private.hh"
Behdad Esfahbodfb194b82011-04-20 02:00:47 -040036#include "hb-unicode-private.hh"
Behdad Esfahbod6b347132007-10-11 08:30:50 +000037
Behdad Esfahbod6b347132007-10-11 08:30:50 +000038
Behdad Esfahbodacdba3f2010-07-23 15:11:18 -040039
Behdad Esfahbod88474c62010-10-27 14:42:15 -040040ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20);
Behdad Esfahbodf1322e52009-08-01 22:53:04 -040041ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t));
42
Behdad Esfahboda7c50462010-10-08 18:47:47 -040043typedef struct _hb_segment_properties_t {
44 hb_direction_t direction;
45 hb_script_t script;
46 hb_language_t language;
47} hb_segment_properties_t;
48
Behdad Esfahbodf1322e52009-08-01 22:53:04 -040049
Behdad Esfahbodd0316a82010-05-12 23:34:52 -040050struct _hb_buffer_t {
Behdad Esfahbodfca368c2011-04-21 18:24:02 -040051 hb_object_header_t header;
Behdad Esfahbodd0316a82010-05-12 23:34:52 -040052
53 /* Information about how the text in the buffer should be treated */
Behdad Esfahbod4e4ef242010-07-23 17:22:11 -040054
Behdad Esfahboda7c50462010-10-08 18:47:47 -040055 hb_unicode_funcs_t *unicode; /* Unicode functions */
56 hb_segment_properties_t props; /* Script, language, direction */
Behdad Esfahbodd0316a82010-05-12 23:34:52 -040057
58 /* Buffer contents */
59
Behdad Esfahbode0db4b82011-04-28 12:56:49 -040060 bool in_error; /* Allocation failed */
Behdad Esfahbodfca368c2011-04-21 18:24:02 -040061 bool have_output; /* Whether we have an output buffer going on */
62 bool have_positions; /* Whether we have positions */
Behdad Esfahbod910a33f2010-05-14 22:13:38 -040063
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -040064 unsigned int idx; /* Cursor into ->info and ->pos arrays */
Behdad Esfahbod910a33f2010-05-14 22:13:38 -040065 unsigned int len; /* Length of ->info and ->pos arrays */
Behdad Esfahbodcc1a8a92011-01-06 14:58:52 -050066 unsigned int out_len; /* Length of ->out array if have_output */
Behdad Esfahbodd0316a82010-05-12 23:34:52 -040067
Behdad Esfahbodc0af1932011-04-15 19:26:24 -040068 unsigned int allocated; /* Length of allocated arrays */
Behdad Esfahbod88474c62010-10-27 14:42:15 -040069 hb_glyph_info_t *info;
70 hb_glyph_info_t *out_info;
71 hb_glyph_position_t *pos;
Behdad Esfahbodd0316a82010-05-12 23:34:52 -040072
Behdad Esfahbodf4a579b2011-07-25 16:20:16 -040073 unsigned int serial;
74 uint8_t allocated_var_bytes[8];
75 const char *allocated_var_owner[8];
76
Behdad Esfahbodd0316a82010-05-12 23:34:52 -040077
78 /* Methods */
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -040079
80 HB_INTERNAL void reset (void);
81
Behdad Esfahbodcc1a8a92011-01-06 14:58:52 -050082 inline unsigned int backtrack_len (void) const
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -040083 { return have_output? out_len : idx; }
Behdad Esfahboddbf56b12010-10-27 17:06:12 -040084 inline unsigned int next_serial (void) { return serial++; }
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -040085
Behdad Esfahbodf4a579b2011-07-25 16:20:16 -040086 HB_INTERNAL void allocate_var (unsigned int byte_i, unsigned int count, const char *owner);
87 HB_INTERNAL void deallocate_var (unsigned int byte_i, unsigned int count, const char *owner);
Behdad Esfahboda9ad3d32011-07-28 15:42:18 -040088 HB_INTERNAL void deallocate_var_all (void);
Behdad Esfahbodf4a579b2011-07-25 16:20:16 -040089
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -040090 HB_INTERNAL void add (hb_codepoint_t codepoint,
91 hb_mask_t mask,
92 unsigned int cluster);
93
94 HB_INTERNAL void reverse_range (unsigned int start, unsigned int end);
95 HB_INTERNAL void reverse (void);
96 HB_INTERNAL void reverse_clusters (void);
Behdad Esfahbod02aeca92011-08-04 22:31:05 -040097 HB_INTERNAL void guess_properties (void);
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -040098
99 HB_INTERNAL void swap_buffers (void);
100 HB_INTERNAL void clear_output (void);
101 HB_INTERNAL void clear_positions (void);
102 HB_INTERNAL void replace_glyphs_be16 (unsigned int num_in,
103 unsigned int num_out,
104 const uint16_t *glyph_data_be);
105 HB_INTERNAL void replace_glyph (hb_codepoint_t glyph_index);
106 /* Makes a copy of the glyph at idx to output and replace glyph_index */
107 HB_INTERNAL void output_glyph (hb_codepoint_t glyph_index);
108 /* Copies glyph at idx to output but doesn't advance idx */
109 HB_INTERNAL void copy_glyph (void);
110 /* Copies glyph at idx to output and advance idx.
111 * If there's no output, just advance idx. */
112 HB_INTERNAL void next_glyph (void);
113 /* Advance idx without copying to output. */
114 inline void skip_glyph (void) { idx++; }
Behdad Esfahbod1ce7b872010-05-21 17:31:45 +0100115
Behdad Esfahbodbd7378b2010-10-13 18:33:16 -0400116 inline void reset_masks (hb_mask_t mask)
117 {
Behdad Esfahbod31f18ab2011-06-15 09:49:58 -0400118 for (unsigned int j = 0; j < len; j++)
119 info[j].mask = mask;
Behdad Esfahbodbd7378b2010-10-13 18:33:16 -0400120 }
121 inline void add_masks (hb_mask_t mask)
122 {
Behdad Esfahbod31f18ab2011-06-15 09:49:58 -0400123 for (unsigned int j = 0; j < len; j++)
124 info[j].mask |= mask;
Behdad Esfahbodbd7378b2010-10-13 18:33:16 -0400125 }
Behdad Esfahbod468e9cb2011-07-22 11:28:07 -0400126 HB_INTERNAL void set_masks (hb_mask_t value,
127 hb_mask_t mask,
128 unsigned int cluster_start,
129 unsigned int cluster_end);
130
131 /* Internal methods */
132 HB_INTERNAL bool enlarge (unsigned int size);
133
134 inline bool ensure (unsigned int size)
135 { return likely (size <= allocated) ? TRUE : enlarge (size); }
136
137 HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out);
Behdad Esfahbode62df432011-08-03 17:38:54 -0400138
139 HB_INTERNAL void *get_scratch_buffer (unsigned int *size);
Behdad Esfahbodd0316a82010-05-12 23:34:52 -0400140};
141
142
Behdad Esfahbodb65c0602011-07-28 16:48:43 -0400143#define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \
144 b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \
145 sizeof (b->info[0].var), owner)
146#define HB_BUFFER_ALLOCATE_VAR(b, var) \
147 HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var)
148#define HB_BUFFER_DEALLOCATE_VAR(b, var) \
149 HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var)
150
151
Behdad Esfahbod6b347132007-10-11 08:30:50 +0000152
Behdad Esfahbodda8edbb2010-06-09 07:15:39 -0400153#endif /* HB_BUFFER_PRIVATE_HH */