hb-buffer-private.hh revision c605bbbb6d4b2a98b1f40ca818760088d991f7d1
1/*
2 * Copyright © 1998-2004  David Turner and Werner Lemberg
3 * Copyright © 2004,2007,2009,2010  Red Hat, Inc.
4 * Copyright © 2011  Google, Inc.
5 *
6 *  This is part of HarfBuzz, a text shaping library.
7 *
8 * 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.
13 *
14 * 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
27 * Google Author(s): Behdad Esfahbod
28 */
29
30#ifndef HB_BUFFER_PRIVATE_HH
31#define HB_BUFFER_PRIVATE_HH
32
33#include "hb-private.hh"
34#include "hb-buffer.h"
35#include "hb-object-private.hh"
36#include "hb-unicode-private.hh"
37
38
39
40ASSERT_STATIC (sizeof (hb_glyph_info_t) == 20);
41ASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t));
42
43typedef 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
49
50struct _hb_buffer_t {
51  hb_object_header_t header;
52
53  /* Information about how the text in the buffer should be treated */
54
55  hb_unicode_funcs_t *unicode; /* Unicode functions */
56  hb_segment_properties_t props; /* Script, language, direction */
57
58  /* Buffer contents */
59
60  bool in_error; /* Allocation failed */
61  bool have_output; /* Whether we have an output buffer going on */
62  bool have_positions; /* Whether we have positions */
63
64  unsigned int idx; /* Cursor into ->info and ->pos arrays */
65  unsigned int len; /* Length of ->info and ->pos arrays */
66  unsigned int out_len; /* Length of ->out array if have_output */
67
68  unsigned int allocated; /* Length of allocated arrays */
69  hb_glyph_info_t     *info;
70  hb_glyph_info_t     *out_info;
71  hb_glyph_position_t *pos;
72
73  unsigned int serial;
74  uint8_t allocated_var_bytes[8];
75  const char *allocated_var_owner[8];
76
77
78  /* Methods */
79
80  HB_INTERNAL void reset (void);
81
82  inline unsigned int backtrack_len (void) const
83  { return have_output? out_len : idx; }
84  inline unsigned int next_serial (void) { return serial++; }
85
86  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);
88  HB_INTERNAL void deallocate_var_all (void);
89
90  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);
97
98  HB_INTERNAL void swap_buffers (void);
99  HB_INTERNAL void clear_output (void);
100  HB_INTERNAL void clear_positions (void);
101  HB_INTERNAL void replace_glyphs_be16 (unsigned int num_in,
102					unsigned int num_out,
103					const uint16_t *glyph_data_be);
104  HB_INTERNAL void replace_glyph (hb_codepoint_t glyph_index);
105  /* Makes a copy of the glyph at idx to output and replace glyph_index */
106  HB_INTERNAL void output_glyph (hb_codepoint_t glyph_index);
107  /* Copies glyph at idx to output but doesn't advance idx */
108  HB_INTERNAL void copy_glyph (void);
109  /* Copies glyph at idx to output and advance idx.
110   * If there's no output, just advance idx. */
111  HB_INTERNAL void next_glyph (void);
112  /* Advance idx without copying to output. */
113  inline void skip_glyph (void) { idx++; }
114
115  inline void reset_masks (hb_mask_t mask)
116  {
117    for (unsigned int j = 0; j < len; j++)
118      info[j].mask = mask;
119  }
120  inline void add_masks (hb_mask_t mask)
121  {
122    for (unsigned int j = 0; j < len; j++)
123      info[j].mask |= mask;
124  }
125  HB_INTERNAL void set_masks (hb_mask_t value,
126			      hb_mask_t mask,
127			      unsigned int cluster_start,
128			      unsigned int cluster_end);
129
130  /* Internal methods */
131  HB_INTERNAL bool enlarge (unsigned int size);
132
133  inline bool ensure (unsigned int size)
134  { return likely (size <= allocated) ? TRUE : enlarge (size); }
135
136  HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out);
137
138  HB_INTERNAL void *get_scratch_buffer (unsigned int *size);
139};
140
141
142#define HB_BUFFER_XALLOCATE_VAR(b, func, var, owner) \
143  b->func (offsetof (hb_glyph_info_t, var) - offsetof(hb_glyph_info_t, var1), \
144	   sizeof (b->info[0].var), owner)
145#define HB_BUFFER_ALLOCATE_VAR(b, var) \
146	HB_BUFFER_XALLOCATE_VAR (b, allocate_var, var (), #var)
147#define HB_BUFFER_DEALLOCATE_VAR(b, var) \
148	HB_BUFFER_XALLOCATE_VAR (b, deallocate_var, var (), #var)
149
150
151
152#endif /* HB_BUFFER_PRIVATE_HH */
153