hb-buffer.cc revision 6b65a76b40522a4f57a6fedcbdfc5a4d736f1d3c
1a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod/* 22409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 1998-2004 David Turner and Werner Lemberg 32409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2004,2007,2009,2010 Red Hat, Inc. 405207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod * Copyright © 2011,2012 Google, Inc. 59f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbod * 68f0d7e0c3fd4b05c43ac449be4f374dc2dc56127Behdad Esfahbod * This is part of HarfBuzz, a text shaping library. 79f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbod * 8a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * Permission is hereby granted, without written agreement and without 9a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this 10a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * software and its documentation for any purpose, provided that the 11a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * above copyright notice and the following two paragraphs appear in 12a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * all copies of this software. 13a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * 14a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 15a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 16a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 17a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 18a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * DAMAGE. 19a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * 20a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 21a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 22a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 23a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 24a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * 26a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod * Red Hat Author(s): Owen Taylor, Behdad Esfahbod 27c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod * Google Author(s): Behdad Esfahbod 289f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbod */ 299f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbod 3022da7fd94d6318c52df69d70470a85464ffc533dBehdad Esfahbod#include "hb-buffer-private.hh" 317f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod#include "hb-utf-private.hh" 329f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbod 33f1322e52d557726baa010be8d35a594748e8fa1aBehdad Esfahbod 34a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod#ifndef HB_DEBUG_BUFFER 35a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod#define HB_DEBUG_BUFFER (HB_DEBUG+0) 36a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod#endif 37a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod 38f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 39f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodhb_bool_t 40f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodhb_segment_properties_equal (const hb_segment_properties_t *a, 41f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod const hb_segment_properties_t *b) 42f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod{ 43f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod return a->direction == b->direction && 44f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod a->script == b->script && 45f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod a->language == b->language && 46f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod a->reserved1 == b->reserved1 && 47f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod a->reserved2 == b->reserved2; 48f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 49f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod} 50f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 51f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodunsigned int 52f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodhb_segment_properties_hash (const hb_segment_properties_t *p) 53f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod{ 54f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod return (unsigned int) p->direction ^ 55f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod (unsigned int) p->script ^ 56f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod (intptr_t) (p->language); 57f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod} 58f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 59f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 60f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 61a8abb8b994c3cd89808e8f7128a0c04b23eb3edeBehdad Esfahbod/* Here is how the buffer works internally: 62a8abb8b994c3cd89808e8f7128a0c04b23eb3edeBehdad Esfahbod * 63910a33fe8457a8e13f7eb77fc92fa59c31f5e8fdBehdad Esfahbod * There are two info pointers: info and out_info. They always have 64910a33fe8457a8e13f7eb77fc92fa59c31f5e8fdBehdad Esfahbod * the same allocated size, but different lengths. 65a8abb8b994c3cd89808e8f7128a0c04b23eb3edeBehdad Esfahbod * 669d5e26df0877aa5b187764ba09bd7bf221e92968Behdad Esfahbod * As an optimization, both info and out_info may point to the 677e7007a1c9bf2c07a8369752126ece8fa6164248Behdad Esfahbod * same piece of memory, which is owned by info. This remains the 68cc1a8a938b4c13e76b58825a9e1951c4134e634aBehdad Esfahbod * case as long as out_len doesn't exceed i at any time. 69468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod * In that case, swap_buffers() is no-op and the glyph operations operate 70910a33fe8457a8e13f7eb77fc92fa59c31f5e8fdBehdad Esfahbod * mostly in-place. 71a8abb8b994c3cd89808e8f7128a0c04b23eb3edeBehdad Esfahbod * 729d5e26df0877aa5b187764ba09bd7bf221e92968Behdad Esfahbod * As soon as out_info gets longer than info, out_info is moved over 73910a33fe8457a8e13f7eb77fc92fa59c31f5e8fdBehdad Esfahbod * to an alternate buffer (which we reuse the pos buffer for!), and its 74910a33fe8457a8e13f7eb77fc92fa59c31f5e8fdBehdad Esfahbod * current contents (out_len entries) are copied to the new place. 75468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod * This should all remain transparent to the user. swap_buffers() then 76910a33fe8457a8e13f7eb77fc92fa59c31f5e8fdBehdad Esfahbod * switches info and out_info. 77a8abb8b994c3cd89808e8f7128a0c04b23eb3edeBehdad Esfahbod */ 78a8abb8b994c3cd89808e8f7128a0c04b23eb3edeBehdad Esfahbod 79c968fc2dc87cf85b53f60a40db59d5ee7b992edfBehdad Esfahbod 80468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 81468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod/* Internal API */ 82468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 83468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodbool 84468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::enlarge (unsigned int size) 853567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod{ 86468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (unlikely (in_error)) 870594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return false; 883567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 89468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int new_allocated = allocated; 90e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod hb_glyph_position_t *new_pos = NULL; 91e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod hb_glyph_info_t *new_info = NULL; 92468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod bool separate_out = out_info != info; 933567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 94468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (unlikely (_hb_unsigned_int_mul_overflows (size, sizeof (info[0])))) 95e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod goto done; 963567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 9738b015e57ffa75d3b078a368c23685beb7c3f946Behdad Esfahbod while (size >= new_allocated) 9865e0063eae2f3adb25315b8bd7b0e7757aa960f3Behdad Esfahbod new_allocated += (new_allocated >> 1) + 32; 993567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 100468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod ASSERT_STATIC (sizeof (info[0]) == sizeof (pos[0])); 101468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (unlikely (_hb_unsigned_int_mul_overflows (new_allocated, sizeof (info[0])))) 102e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod goto done; 103e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod 104468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod new_pos = (hb_glyph_position_t *) realloc (pos, new_allocated * sizeof (pos[0])); 105468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod new_info = (hb_glyph_info_t *) realloc (info, new_allocated * sizeof (info[0])); 1063567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 107e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahboddone: 1083567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod if (unlikely (!new_pos || !new_info)) 1090594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod in_error = true; 1103567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 1113567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod if (likely (new_pos)) 112468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod pos = new_pos; 1133567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 1143567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod if (likely (new_info)) 115468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod info = new_info; 116468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 117468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_info = separate_out ? (hb_glyph_info_t *) pos : info; 118468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (likely (!in_error)) 119468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod allocated = new_allocated; 120468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 121468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod return likely (!in_error); 122468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 123468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 124468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodbool 125468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::make_room_for (unsigned int num_in, 126468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int num_out) 127468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 1280594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod if (unlikely (!ensure (out_len + num_out))) return false; 129468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 130468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (out_info == info && 131468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_len + num_out > idx + num_in) 132468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod { 133468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod assert (have_output); 134468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 135468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_info = (hb_glyph_info_t *) pos; 136468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod memcpy (out_info, info, out_len * sizeof (out_info[0])); 137468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod } 138468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 1390594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return true; 140468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 141468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 1426b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbodbool 1436b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbodhb_buffer_t::shift_forward (unsigned int count) 1446b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod{ 1456b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod assert (have_output); 1466b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod if (unlikely (!ensure (len + count))) return false; 1476b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod 1486b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod memmove (info + idx + count, info + idx, (len - idx) * sizeof (info[0])); 1496b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod len += count; 1506b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod idx += count; 1516b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod 1526b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod return true; 1536b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod} 1546b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod 155e62df43649e31b7815c272f01808b3f726c7d07dBehdad Esfahbodvoid * 156e62df43649e31b7815c272f01808b3f726c7d07dBehdad Esfahbodhb_buffer_t::get_scratch_buffer (unsigned int *size) 157e62df43649e31b7815c272f01808b3f726c7d07dBehdad Esfahbod{ 1580594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod have_output = false; 1590594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod have_positions = false; 16047ef931f13778b894090139a64238a5ab9ac1154Behdad Esfahbod 161e62df43649e31b7815c272f01808b3f726c7d07dBehdad Esfahbod out_len = 0; 16247ef931f13778b894090139a64238a5ab9ac1154Behdad Esfahbod out_info = info; 16347ef931f13778b894090139a64238a5ab9ac1154Behdad Esfahbod 164e62df43649e31b7815c272f01808b3f726c7d07dBehdad Esfahbod *size = allocated * sizeof (pos[0]); 165e62df43649e31b7815c272f01808b3f726c7d07dBehdad Esfahbod return pos; 166e62df43649e31b7815c272f01808b3f726c7d07dBehdad Esfahbod} 167e62df43649e31b7815c272f01808b3f726c7d07dBehdad Esfahbod 168468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 16969cc492dc120847ed00cae65ec958593ebf550c5Behdad Esfahbod 170468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod/* HarfBuzz-Internal API */ 171468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 172468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 173468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::reset (void) 174468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 175468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (unlikely (hb_object_is_inert (this))) 176468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod return; 177468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 178468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod hb_unicode_funcs_destroy (unicode); 179d5045a5f4017631a4660f985fe451c5a64c42ca0Behdad Esfahbod unicode = hb_unicode_funcs_get_default (); 180468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 18182ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod clear (); 18282ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod} 18382ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod 18482ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbodvoid 18582ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbodhb_buffer_t::clear (void) 18682ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod{ 18782ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod if (unlikely (hb_object_is_inert (this))) 18882ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod return; 18982ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod 190f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_segment_properties_t default_props = HB_SEGMENT_PROPERTIES_DEFAULT; 191f06ab8a4262c759b4723614fd28f55ee77aa8466Behdad Esfahbod props = default_props; 1924dc798de19c767b91fd3025c85593fa6809d1340Behdad Esfahbod flags = HB_BUFFER_FLAG_DEFAULT; 193468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 19496fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod content_type = HB_BUFFER_CONTENT_TYPE_INVALID; 1950594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod in_error = false; 1960594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod have_output = false; 1970594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod have_positions = false; 1983567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 199468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod idx = 0; 200468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod len = 0; 201468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_len = 0; 20247ef931f13778b894090139a64238a5ab9ac1154Behdad Esfahbod out_info = info; 2033567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 204468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod serial = 0; 205f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod memset (allocated_var_bytes, 0, sizeof allocated_var_bytes); 206f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod memset (allocated_var_owner, 0, sizeof allocated_var_owner); 20705207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod 20805207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod memset (context, 0, sizeof context); 20905207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod memset (context_len, 0, sizeof context_len); 2103567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod} 2113567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 212468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 213468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::add (hb_codepoint_t codepoint, 214468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int cluster) 2153567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod{ 216468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod hb_glyph_info_t *glyph; 217468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 218468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (unlikely (!ensure (len + 1))) return; 219468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 220468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod glyph = &info[len]; 221468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 222468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod memset (glyph, 0, sizeof (*glyph)); 223468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod glyph->codepoint = codepoint; 22466ac2ff32e24f0d5658ca172147613081a133847Behdad Esfahbod glyph->mask = 1; 225468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod glyph->cluster = cluster; 226468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 227468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod len++; 2283567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod} 2296b347138b597c41af24453f630336ba2fc033dc5Behdad Esfahbod 230468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 231847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbodhb_buffer_t::add_info (const hb_glyph_info_t &glyph_info) 232847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbod{ 233847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbod if (unlikely (!ensure (len + 1))) return; 234847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbod 235847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbod info[len] = glyph_info; 236847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbod 237847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbod len++; 238847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbod} 239847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbod 240847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbod 241847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbodvoid 2420bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbodhb_buffer_t::remove_output (void) 2430bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod{ 2440bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod if (unlikely (hb_object_is_inert (this))) 2450bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod return; 2460bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod 2470bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod have_output = false; 2480bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod have_positions = false; 2490bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod 2500bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod out_len = 0; 2510bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod out_info = info; 2520bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod} 2530bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbod 2540bc7a38463bfb37f12efeb1b8cb2024cf4a347bcBehdad Esfahbodvoid 255468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::clear_output (void) 256c968fc2dc87cf85b53f60a40db59d5ee7b992edfBehdad Esfahbod{ 257468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (unlikely (hb_object_is_inert (this))) 258468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod return; 259468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 2600594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod have_output = true; 2610594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod have_positions = false; 262a6a79df5fe2ed2cd307e7a991346faee164e70d9Behdad Esfahbod 263468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_len = 0; 264468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_info = info; 265468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 266468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 267468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 268468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::clear_positions (void) 269468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 270468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (unlikely (hb_object_is_inert (this))) 271468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod return; 272468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 2730594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod have_output = false; 2740594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod have_positions = true; 275468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 27647ef931f13778b894090139a64238a5ab9ac1154Behdad Esfahbod out_len = 0; 27747ef931f13778b894090139a64238a5ab9ac1154Behdad Esfahbod out_info = info; 27847ef931f13778b894090139a64238a5ab9ac1154Behdad Esfahbod 279468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod memset (pos, 0, sizeof (pos[0]) * len); 280468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 281468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 282468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 283468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::swap_buffers (void) 284468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 285468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (unlikely (in_error)) return; 286468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 287468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod assert (have_output); 2880594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod have_output = false; 289468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 290468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (out_info != info) 291e35bbd570a5d914f86f1ea83941ee4328f268059Behdad Esfahbod { 292468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod hb_glyph_info_t *tmp_string; 293468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod tmp_string = info; 294468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod info = out_info; 295468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_info = tmp_string; 296468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod pos = (hb_glyph_position_t *) out_info; 297468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod } 298468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 299468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int tmp; 300468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod tmp = len; 301468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod len = out_len; 302468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_len = tmp; 303468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 304468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod idx = 0; 305468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 306e35bbd570a5d914f86f1ea83941ee4328f268059Behdad Esfahbod 30769cc492dc120847ed00cae65ec958593ebf550c5Behdad Esfahbod 308468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 3099ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbodhb_buffer_t::replace_glyphs (unsigned int num_in, 3109ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod unsigned int num_out, 3118e3715f8a16b315c1c7dd4b256e7f68a36c53e7cBehdad Esfahbod const uint32_t *glyph_data) 3129ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod{ 31369cc492dc120847ed00cae65ec958593ebf550c5Behdad Esfahbod if (unlikely (!make_room_for (num_in, num_out))) return; 3149ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod 315e88e14421a33ca5bdfd76bc0b2f801fcb6e78911Behdad Esfahbod merge_clusters (idx, idx + num_in); 3169ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod 317e88e14421a33ca5bdfd76bc0b2f801fcb6e78911Behdad Esfahbod hb_glyph_info_t orig_info = info[idx]; 3189ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod hb_glyph_info_t *pinfo = &out_info[out_len]; 3199ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod for (unsigned int i = 0; i < num_out; i++) 3209ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod { 3219ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod *pinfo = orig_info; 3229ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod pinfo->codepoint = glyph_data[i]; 3239ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod pinfo++; 3249ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod } 3259ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod 3269ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod idx += num_in; 3279ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod out_len += num_out; 3289ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod} 3299ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbod 3309ebe8c0286856d46430ae184ba7303bd34485883Behdad Esfahbodvoid 331468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::output_glyph (hb_codepoint_t glyph_index) 332468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 33369cc492dc120847ed00cae65ec958593ebf550c5Behdad Esfahbod if (unlikely (!make_room_for (0, 1))) return; 334468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 335468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_info[out_len] = info[idx]; 336468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_info[out_len].codepoint = glyph_index; 337468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 338468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_len++; 339468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 340468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 341468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 342847794e929831750e97525137ab5e285ccd1064eBehdad Esfahbodhb_buffer_t::output_info (const hb_glyph_info_t &glyph_info) 343b85800f9de8976a7418ef9df467d3080c6ab0199Behdad Esfahbod{ 344b85800f9de8976a7418ef9df467d3080c6ab0199Behdad Esfahbod if (unlikely (!make_room_for (0, 1))) return; 345b85800f9de8976a7418ef9df467d3080c6ab0199Behdad Esfahbod 346b85800f9de8976a7418ef9df467d3080c6ab0199Behdad Esfahbod out_info[out_len] = glyph_info; 347b85800f9de8976a7418ef9df467d3080c6ab0199Behdad Esfahbod 348b85800f9de8976a7418ef9df467d3080c6ab0199Behdad Esfahbod out_len++; 349b85800f9de8976a7418ef9df467d3080c6ab0199Behdad Esfahbod} 350b85800f9de8976a7418ef9df467d3080c6ab0199Behdad Esfahbod 351b85800f9de8976a7418ef9df467d3080c6ab0199Behdad Esfahbodvoid 352468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::copy_glyph (void) 353468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 35469cc492dc120847ed00cae65ec958593ebf550c5Behdad Esfahbod if (unlikely (!make_room_for (0, 1))) return; 355468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 356468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_info[out_len] = info[idx]; 357468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 358468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_len++; 359468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 360468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 3616b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbodbool 3626b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbodhb_buffer_t::move_to (unsigned int i) 3636b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod{ 3646b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod if (!have_output) 3656b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod { 3666b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod assert (i <= len); 3676b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod idx = i; 3686b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod } 3696b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod else if (out_len < i) 3706b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod { 3716b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod unsigned int count = i - out_len; 3726b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod if (unlikely (!make_room_for (count, count))) return false; 3736b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod 3746b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod memmove (out_info + out_len, info + idx, count * sizeof (out_info[0])); 3756b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod idx += count; 3766b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod out_len += count; 3776b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod } 3786b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod else if (out_len > i) 3796b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod { 3806b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod /* Tricky part: rewinding... */ 3816b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod unsigned int count = out_len - i; 3826b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod 3836b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod if (unlikely (idx < count && !shift_forward (count + 32))) return false; 3846b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod 3856b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod assert (idx >= count); 3866b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod 3876b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod idx -= count; 3886b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod out_len -= count; 3896b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod memmove (info + idx, out_info + out_len, count * sizeof (out_info[0])); 3906b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod } 3916b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod return true; 3926b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod} 3936b65a76b40522a4f57a6fedcbdfc5a4d736f1d3cBehdad Esfahbod 394468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 395468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::replace_glyph (hb_codepoint_t glyph_index) 396468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 39769cc492dc120847ed00cae65ec958593ebf550c5Behdad Esfahbod if (unlikely (out_info != info || out_len != idx)) { 39869cc492dc120847ed00cae65ec958593ebf550c5Behdad Esfahbod if (unlikely (!make_room_for (1, 1))) return; 39969cc492dc120847ed00cae65ec958593ebf550c5Behdad Esfahbod out_info[out_len] = info[idx]; 40069cc492dc120847ed00cae65ec958593ebf550c5Behdad Esfahbod } 401468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_info[out_len].codepoint = glyph_index; 402468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 403468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod idx++; 404468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod out_len++; 405468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 406468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 40769cc492dc120847ed00cae65ec958593ebf550c5Behdad Esfahbod 408468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 409468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::set_masks (hb_mask_t value, 410468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod hb_mask_t mask, 411468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int cluster_start, 412468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int cluster_end) 413468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 414468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod hb_mask_t not_mask = ~mask; 415468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod value &= mask; 416468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 417468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (!mask) 418468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod return; 419468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 420468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (cluster_start == 0 && cluster_end == (unsigned int)-1) { 421468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int count = len; 422468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod for (unsigned int i = 0; i < count; i++) 423468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod info[i].mask = (info[i].mask & not_mask) | value; 424468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod return; 425468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod } 426468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 427468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int count = len; 428468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod for (unsigned int i = 0; i < count; i++) 429468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (cluster_start <= info[i].cluster && info[i].cluster < cluster_end) 430468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod info[i].mask = (info[i].mask & not_mask) | value; 431468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 432468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 433468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 434468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::reverse_range (unsigned int start, 435468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int end) 436468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 437468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int i, j; 438468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 439468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (start == end - 1) 440468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod return; 441468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 442468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod for (i = start, j = end - 1; i < j; i++, j--) { 443468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod hb_glyph_info_t t; 444468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 445468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod t = info[i]; 446468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod info[i] = info[j]; 447468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod info[j] = t; 448468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod } 449468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 450468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (pos) { 451468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod for (i = start, j = end - 1; i < j; i++, j--) { 452468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod hb_glyph_position_t t; 453468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 454468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod t = pos[i]; 455468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod pos[i] = pos[j]; 456468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod pos[j] = t; 457468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod } 458468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod } 459468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 460468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 461468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 462468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::reverse (void) 463468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 464468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (unlikely (!len)) 465468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod return; 466468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 467468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod reverse_range (0, len); 468468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod} 469468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 470468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodvoid 471468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbodhb_buffer_t::reverse_clusters (void) 472468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod{ 473468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int i, start, count, last_cluster; 474468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 475468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (unlikely (!len)) 476468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod return; 477468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 478468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod reverse (); 479468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 480468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod count = len; 481468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod start = 0; 482468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod last_cluster = info[0].cluster; 483468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod for (i = 1; i < count; i++) { 484468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (last_cluster != info[i].cluster) { 485468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod reverse_range (start, i); 486468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod start = i; 487468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod last_cluster = info[i].cluster; 488468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod } 489468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod } 490468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod reverse_range (start, i); 491a8abb8b994c3cd89808e8f7128a0c04b23eb3edeBehdad Esfahbod} 492a8abb8b994c3cd89808e8f7128a0c04b23eb3edeBehdad Esfahbod 49302aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbodvoid 494d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbodhb_buffer_t::merge_clusters (unsigned int start, 495d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod unsigned int end) 496d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod{ 497fe3dabc08df7501010564f8844bd4d11771cc6a4Behdad Esfahbod if (unlikely (end - start < 2)) 498cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod return; 499cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod 500cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod unsigned int cluster = info[start].cluster; 501d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod 502d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod for (unsigned int i = start + 1; i < end; i++) 503cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod cluster = MIN (cluster, info[i].cluster); 504cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod 505cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod /* Extend end */ 506cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod while (end < len && info[end - 1].cluster == info[end].cluster) 507cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod end++; 508cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod 509cd5891493df06fdb92e1ae526d29dee8df250235Behdad Esfahbod /* Extend start */ 510cd5891493df06fdb92e1ae526d29dee8df250235Behdad Esfahbod while (idx < start && info[start - 1].cluster == info[start].cluster) 511cd5891493df06fdb92e1ae526d29dee8df250235Behdad Esfahbod start--; 512cd5891493df06fdb92e1ae526d29dee8df250235Behdad Esfahbod 513cd5891493df06fdb92e1ae526d29dee8df250235Behdad Esfahbod /* If we hit the start of buffer, continue in out-buffer. */ 514cd5891493df06fdb92e1ae526d29dee8df250235Behdad Esfahbod if (idx == start) 515cd5891493df06fdb92e1ae526d29dee8df250235Behdad Esfahbod for (unsigned i = out_len; i && out_info[i - 1].cluster == info[start].cluster; i--) 516cd5891493df06fdb92e1ae526d29dee8df250235Behdad Esfahbod out_info[i - 1].cluster = cluster; 517cd5891493df06fdb92e1ae526d29dee8df250235Behdad Esfahbod 518d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod for (unsigned int i = start; i < end; i++) 519cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod info[i].cluster = cluster; 520d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod} 521d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbodvoid 522d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbodhb_buffer_t::merge_out_clusters (unsigned int start, 523d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod unsigned int end) 524d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod{ 525fe3dabc08df7501010564f8844bd4d11771cc6a4Behdad Esfahbod if (unlikely (end - start < 2)) 52672c0a1878313e7232d554bc226f4c6dc01418a95Behdad Esfahbod return; 52772c0a1878313e7232d554bc226f4c6dc01418a95Behdad Esfahbod 528cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod unsigned int cluster = out_info[start].cluster; 529d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod 530d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod for (unsigned int i = start + 1; i < end; i++) 531cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod cluster = MIN (cluster, out_info[i].cluster); 53272c0a1878313e7232d554bc226f4c6dc01418a95Behdad Esfahbod 53372c0a1878313e7232d554bc226f4c6dc01418a95Behdad Esfahbod /* Extend start */ 53472c0a1878313e7232d554bc226f4c6dc01418a95Behdad Esfahbod while (start && out_info[start - 1].cluster == out_info[start].cluster) 53572c0a1878313e7232d554bc226f4c6dc01418a95Behdad Esfahbod start--; 53672c0a1878313e7232d554bc226f4c6dc01418a95Behdad Esfahbod 5375ced012d9f58c51d557a835593c3277e35fe3b35Behdad Esfahbod /* Extend end */ 5385ced012d9f58c51d557a835593c3277e35fe3b35Behdad Esfahbod while (end < out_len && out_info[end - 1].cluster == out_info[end].cluster) 5395ced012d9f58c51d557a835593c3277e35fe3b35Behdad Esfahbod end++; 5405ced012d9f58c51d557a835593c3277e35fe3b35Behdad Esfahbod 541e51d2b6ed1c794ac28c5610bfd01dbc9fb383633Behdad Esfahbod /* If we hit the end of out-buffer, continue in buffer. */ 542e51d2b6ed1c794ac28c5610bfd01dbc9fb383633Behdad Esfahbod if (end == out_len) 543e51d2b6ed1c794ac28c5610bfd01dbc9fb383633Behdad Esfahbod for (unsigned i = idx; i < len && info[i].cluster == out_info[end - 1].cluster; i++) 544e51d2b6ed1c794ac28c5610bfd01dbc9fb383633Behdad Esfahbod info[i].cluster = cluster; 545e51d2b6ed1c794ac28c5610bfd01dbc9fb383633Behdad Esfahbod 546d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod for (unsigned int i = start; i < end; i++) 547cafa6f372721fd6b0a7c0da68b9421d3e94931bcBehdad Esfahbod out_info[i].cluster = cluster; 548d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod} 549d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbod 550d4cc44716c1e098f8abbc0e495404598026ef242Behdad Esfahbodvoid 5513f82f8ff07a9d16a7c047129658c1bbedfdb5436Behdad Esfahbodhb_buffer_t::guess_segment_properties (void) 55202aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod{ 5538465a05a89742295d4b009a9b4442eb0a899fd80Behdad Esfahbod assert (content_type == HB_BUFFER_CONTENT_TYPE_UNICODE || 5548465a05a89742295d4b009a9b4442eb0a899fd80Behdad Esfahbod (!len && content_type == HB_BUFFER_CONTENT_TYPE_INVALID)); 55596fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod 55602aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod /* If script is set to INVALID, guess from buffer contents */ 55702aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod if (props.script == HB_SCRIPT_INVALID) { 55802aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod for (unsigned int i = 0; i < len; i++) { 559208f70f0553d73d2908b21b9552298029482a8b9Behdad Esfahbod hb_script_t script = unicode->script (info[i].codepoint); 56002aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod if (likely (script != HB_SCRIPT_COMMON && 56102aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod script != HB_SCRIPT_INHERITED && 56202aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod script != HB_SCRIPT_UNKNOWN)) { 56302aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod props.script = script; 56402aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod break; 56502aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod } 56602aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod } 56702aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod } 56802aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod 56902aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod /* If direction is set to INVALID, guess from script */ 57002aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod if (props.direction == HB_DIRECTION_INVALID) { 57102aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod props.direction = hb_script_get_horizontal_direction (props.script); 57202aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod } 57302aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod 57402aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod /* If language is not set, use default language from locale */ 57502aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod if (props.language == HB_LANGUAGE_INVALID) { 57602aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod /* TODO get_default_for_script? using $LANGUAGE */ 57702aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod props.language = hb_language_get_default (); 57802aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod } 57902aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod} 58002aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod 58102aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod 582a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbodstatic inline void 583a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahboddump_var_allocation (const hb_buffer_t *buffer) 584a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod{ 585a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod char buf[80]; 586a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod for (unsigned int i = 0; i < 8; i++) 587b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod buf[i] = '0' + buffer->allocated_var_bytes[7 - i]; 588a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod buf[8] = '\0'; 589a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod DEBUG_MSG (BUFFER, buffer, 590a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod "Current var allocation: %s", 591a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod buf); 592a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod} 5933567b87cce541dfb0af7caf024ec67c9d3c09214Behdad Esfahbod 594f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbodvoid hb_buffer_t::allocate_var (unsigned int byte_i, unsigned int count, const char *owner) 595f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod{ 596b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod assert (byte_i < 8 && byte_i + count <= 8); 597a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod 5986c15ddfe2b45383824b64058ae69939d002183a6Behdad Esfahbod if (DEBUG_ENABLED (BUFFER)) 599a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod dump_var_allocation (this); 600a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod DEBUG_MSG (BUFFER, this, 601a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod "Allocating var bytes %d..%d for %s", 602a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod byte_i, byte_i + count - 1, owner); 603a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod 604f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod for (unsigned int i = byte_i; i < byte_i + count; i++) { 605f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod assert (!allocated_var_bytes[i]); 606f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod allocated_var_bytes[i]++; 607f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod allocated_var_owner[i] = owner; 608f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod } 609f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod} 610f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod 611f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbodvoid hb_buffer_t::deallocate_var (unsigned int byte_i, unsigned int count, const char *owner) 612f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod{ 6136c15ddfe2b45383824b64058ae69939d002183a6Behdad Esfahbod if (DEBUG_ENABLED (BUFFER)) 614b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod dump_var_allocation (this); 615b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod 616a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod DEBUG_MSG (BUFFER, this, 617a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod "Deallocating var bytes %d..%d for %s", 618a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod byte_i, byte_i + count - 1, owner); 619a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod 620b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod assert (byte_i < 8 && byte_i + count <= 8); 621f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod for (unsigned int i = byte_i; i < byte_i + count; i++) { 622b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod assert (allocated_var_bytes[i]); 623b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod assert (0 == strcmp (allocated_var_owner[i], owner)); 624f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod allocated_var_bytes[i]--; 625f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod } 626f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod} 627f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod 628965c280de09b49d711cb78d629da321c802084deBehdad Esfahbodvoid hb_buffer_t::assert_var (unsigned int byte_i, unsigned int count, const char *owner) 629965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod{ 6306c15ddfe2b45383824b64058ae69939d002183a6Behdad Esfahbod if (DEBUG_ENABLED (BUFFER)) 631965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod dump_var_allocation (this); 632965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod 633965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod DEBUG_MSG (BUFFER, this, 634965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod "Asserting var bytes %d..%d for %s", 635965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod byte_i, byte_i + count - 1, owner); 636965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod 637965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod assert (byte_i < 8 && byte_i + count <= 8); 638965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod for (unsigned int i = byte_i; i < byte_i + count; i++) { 639965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod assert (allocated_var_bytes[i]); 640965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod assert (0 == strcmp (allocated_var_owner[i], owner)); 641965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod } 642965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod} 643965c280de09b49d711cb78d629da321c802084deBehdad Esfahbod 644a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbodvoid hb_buffer_t::deallocate_var_all (void) 645a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod{ 646a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod memset (allocated_var_bytes, 0, sizeof (allocated_var_bytes)); 647a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod memset (allocated_var_owner, 0, sizeof (allocated_var_owner)); 648a9ad3d3460ba863a8d8f3766ccbeab288c3c6822Behdad Esfahbod} 649f4a579bc42fb811ff5c391a0e97b7d8656ef59b1Behdad Esfahbod 6506b347138b597c41af24453f630336ba2fc033dc5Behdad Esfahbod/* Public API */ 6516b347138b597c41af24453f630336ba2fc033dc5Behdad Esfahbod 652288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 653085d4291a9f253a4b8e2eec8003ac11d02a9394fBehdad Esfahbod * hb_buffer_create: (Xconstructor) 654288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 655288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 656288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 657288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: (transfer full) 658288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 659288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 660288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 661b857b49c82782d29d6d189f1a9f4a84d39cd84eaBehdad Esfahbodhb_buffer_t * 662c54599ad269380c7aa28d885fcfd660fc2c10a7bBehdad Esfahbodhb_buffer_create (void) 6639f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbod{ 664b857b49c82782d29d6d189f1a9f4a84d39cd84eaBehdad Esfahbod hb_buffer_t *buffer; 665b857b49c82782d29d6d189f1a9f4a84d39cd84eaBehdad Esfahbod 66647e71d9661946a4ffb96026bf1d697d788414ab5Behdad Esfahbod if (!(buffer = hb_object_create<hb_buffer_t> ())) 667f06ab8a4262c759b4723614fd28f55ee77aa8466Behdad Esfahbod return hb_buffer_get_empty (); 6689f8da38cd108590514b71756b752d98952a9221fBehdad Esfahbod 669468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod buffer->reset (); 6705ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod 67111fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod return buffer; 67211fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod} 6737a26864308bd1ca8d5f47d798411cac7239b7d38Behdad Esfahbod 674288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 675288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_get_empty: 676288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 677288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 678288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 679288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: (transfer full): 680288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 681288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 682288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 68311fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbodhb_buffer_t * 68480a6833b032bc63b4e8c3da6489d3767af1168f3Behdad Esfahbodhb_buffer_get_empty (void) 68580a6833b032bc63b4e8c3da6489d3767af1168f3Behdad Esfahbod{ 686f06ab8a4262c759b4723614fd28f55ee77aa8466Behdad Esfahbod static const hb_buffer_t _hb_buffer_nil = { 687f06ab8a4262c759b4723614fd28f55ee77aa8466Behdad Esfahbod HB_OBJECT_HEADER_STATIC, 688f06ab8a4262c759b4723614fd28f55ee77aa8466Behdad Esfahbod 689d5045a5f4017631a4660f985fe451c5a64c42ca0Behdad Esfahbod const_cast<hb_unicode_funcs_t *> (&_hb_unicode_funcs_nil), 690f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod HB_SEGMENT_PROPERTIES_DEFAULT, 6914dc798de19c767b91fd3025c85593fa6809d1340Behdad Esfahbod HB_BUFFER_FLAG_DEFAULT, 692f06ab8a4262c759b4723614fd28f55ee77aa8466Behdad Esfahbod 69396fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod HB_BUFFER_CONTENT_TYPE_INVALID, 6940594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod true, /* in_error */ 6950594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod true, /* have_output */ 6960594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod true /* have_positions */ 69705207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod 69805207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod /* Zero is good enough for everything else. */ 699f06ab8a4262c759b4723614fd28f55ee77aa8466Behdad Esfahbod }; 700f06ab8a4262c759b4723614fd28f55ee77aa8466Behdad Esfahbod 701f06ab8a4262c759b4723614fd28f55ee77aa8466Behdad Esfahbod return const_cast<hb_buffer_t *> (&_hb_buffer_nil); 70280a6833b032bc63b4e8c3da6489d3767af1168f3Behdad Esfahbod} 70380a6833b032bc63b4e8c3da6489d3767af1168f3Behdad Esfahbod 704288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 705288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_reference: (skip) 706288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 707288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 708288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 709288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 710288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: (transfer full): 711288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 712288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 713288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 71480a6833b032bc63b4e8c3da6489d3767af1168f3Behdad Esfahbodhb_buffer_t * 71511fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbodhb_buffer_reference (hb_buffer_t *buffer) 71611fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod{ 71747e71d9661946a4ffb96026bf1d697d788414ab5Behdad Esfahbod return hb_object_reference (buffer); 71811fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod} 719f9cd1014f8f4d0394b5e0e9eefc1e2af13c59cabBehdad Esfahbod 720288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 721288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_destroy: (skip) 722288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 723288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 724288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 725288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 726288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 727288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 7287a26864308bd1ca8d5f47d798411cac7239b7d38Behdad Esfahbodvoid 72911fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbodhb_buffer_destroy (hb_buffer_t *buffer) 7307a26864308bd1ca8d5f47d798411cac7239b7d38Behdad Esfahbod{ 73147e71d9661946a4ffb96026bf1d697d788414ab5Behdad Esfahbod if (!hb_object_destroy (buffer)) return; 73211fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod 7335ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod hb_unicode_funcs_destroy (buffer->unicode); 7345ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod 7357e7007a1c9bf2c07a8369752126ece8fa6164248Behdad Esfahbod free (buffer->info); 7361b621823f3e31b48c80cc8b0691dfa873ba086cdBehdad Esfahbod free (buffer->pos); 73711fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod 738b857b49c82782d29d6d189f1a9f4a84d39cd84eaBehdad Esfahbod free (buffer); 7397a26864308bd1ca8d5f47d798411cac7239b7d38Behdad Esfahbod} 7407a26864308bd1ca8d5f47d798411cac7239b7d38Behdad Esfahbod 741288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 742288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_set_user_data: (skip) 743288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 744288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @key: 745288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @data: 746288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @destroy: 747288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @replace: 748288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 749288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 750288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 751288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 752288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 753288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 754288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 7555fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbodhb_bool_t 7565fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbodhb_buffer_set_user_data (hb_buffer_t *buffer, 7575fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbod hb_user_data_key_t *key, 7585fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbod void * data, 75933ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod hb_destroy_func_t destroy, 76033ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod hb_bool_t replace) 7615fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbod{ 76233ccc77902660ed4b49184e5ec99f4fd0ef63175Behdad Esfahbod return hb_object_set_user_data (buffer, key, data, destroy, replace); 7635fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbod} 7645fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbod 765288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 766288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_get_user_data: (skip) 767288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 768288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @key: 769288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 770288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 771288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 772288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 773288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 774288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 775288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 7765fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbodvoid * 7775fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbodhb_buffer_get_user_data (hb_buffer_t *buffer, 7785fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbod hb_user_data_key_t *key) 7795fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbod{ 7805fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbod return hb_object_get_user_data (buffer, key); 7815fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbod} 7825fa849b77d49da2212825ebb1bea9145713b8449Behdad Esfahbod 7835ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod 784288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 785288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_set_content_type: 786288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 787288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @content_type: 788288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 789288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 790288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 791288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 792288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 7935ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbodvoid 79496fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbodhb_buffer_set_content_type (hb_buffer_t *buffer, 79596fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod hb_buffer_content_type_t content_type) 79696fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod{ 79796fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod buffer->content_type = content_type; 79896fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod} 79996fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod 800288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 801288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_get_content_type: 802288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 803288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 804288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 805288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 806288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 807288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 808288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 809288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 81096fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbodhb_buffer_content_type_t 81196fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbodhb_buffer_get_content_type (hb_buffer_t *buffer) 81296fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod{ 81396fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod return buffer->content_type; 81496fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod} 81596fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod 81696fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbod 817288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 818288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_set_unicode_funcs: 819288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 820288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @unicode_funcs: 821288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 822288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 823288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 824288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 825288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 82696fdc04e5c6daafce3d45e7508418e4db94df44cBehdad Esfahbodvoid 8275ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbodhb_buffer_set_unicode_funcs (hb_buffer_t *buffer, 828288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod hb_unicode_funcs_t *unicode_funcs) 8295ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod{ 830e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod if (unlikely (hb_object_is_inert (buffer))) 831e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod return; 832e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod 833288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod if (!unicode_funcs) 834288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod unicode_funcs = hb_unicode_funcs_get_default (); 835d5045a5f4017631a4660f985fe451c5a64c42ca0Behdad Esfahbod 8360465e69832393cc1ed36508ec5d597fbab64877aBehdad Esfahbod 837288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod hb_unicode_funcs_reference (unicode_funcs); 8385ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod hb_unicode_funcs_destroy (buffer->unicode); 839288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod buffer->unicode = unicode_funcs; 8405ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod} 8415ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod 842288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 843288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_get_unicode_funcs: 844288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 845288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 846288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 847288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 848288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 849288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 850288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 851288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 8525ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbodhb_unicode_funcs_t * 8535ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbodhb_buffer_get_unicode_funcs (hb_buffer_t *buffer) 8545ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod{ 8555ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod return buffer->unicode; 8565ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod} 8575ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod 858288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 859288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_set_direction: 860288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 861288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @direction: 862288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 863288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 864288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 865288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 866288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 8675ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbodvoid 8685ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbodhb_buffer_set_direction (hb_buffer_t *buffer, 8695ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod hb_direction_t direction) 8705ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod 8715ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod{ 872e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod if (unlikely (hb_object_is_inert (buffer))) 873e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod return; 874e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod 8754e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod buffer->props.direction = direction; 8765ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod} 8775ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod 878288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 879288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_get_direction: 880288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 881288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 882288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 883288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 884288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 885288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 886288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 887288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 8885ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbodhb_direction_t 8895ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbodhb_buffer_get_direction (hb_buffer_t *buffer) 8905ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod{ 8914e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod return buffer->props.direction; 8925ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod} 8935ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod 894288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 895288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_set_script: 896288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 897288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @script: 898288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 899288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 900288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 901288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 902288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 903ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbodvoid 904ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbodhb_buffer_set_script (hb_buffer_t *buffer, 905ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod hb_script_t script) 906ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod{ 907e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod if (unlikely (hb_object_is_inert (buffer))) 908e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod return; 909e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod 9104e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod buffer->props.script = script; 911ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod} 912ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod 913288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 914288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_get_script: 915288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 916288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 917288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 918288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 919288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 920288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 921288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 922288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 923ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbodhb_script_t 924ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbodhb_buffer_get_script (hb_buffer_t *buffer) 925ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod{ 9264e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod return buffer->props.script; 927ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod} 928ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod 929288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 930288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_set_language: 931288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 932288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @language: 933288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 934288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 935288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 936288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 937288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 938ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbodvoid 939ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbodhb_buffer_set_language (hb_buffer_t *buffer, 940ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod hb_language_t language) 941ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod{ 942e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod if (unlikely (hb_object_is_inert (buffer))) 943e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod return; 944e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod 9454e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod buffer->props.language = language; 946ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod} 947ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod 948288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 949288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_get_language: 950288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 951288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 952288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 953288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 954288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 955288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 956288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 957288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 958ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbodhb_language_t 959ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbodhb_buffer_get_language (hb_buffer_t *buffer) 960ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod{ 9614e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod return buffer->props.language; 962ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod} 963ae070b7d39d03bd8bc1244f687b24db505f4af3fBehdad Esfahbod 964288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 965288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_set_segment_properties: 966288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 967288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @props: 968288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 969288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 970288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 971288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 972288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 9730c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbodvoid 974f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodhb_buffer_set_segment_properties (hb_buffer_t *buffer, 975f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod const hb_segment_properties_t *props) 976f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod{ 977f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod if (unlikely (hb_object_is_inert (buffer))) 978f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod return; 979f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 980f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod buffer->props = *props; 981f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod} 982f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 983288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 984288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_get_segment_properties: 985288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 986288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @props: 987288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 988288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 989288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 990288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 991288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 992f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodvoid 993f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodhb_buffer_get_segment_properties (hb_buffer_t *buffer, 994f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_segment_properties_t *props) 995f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod{ 996f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod *props = buffer->props; 997f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod} 998f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 999f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 1000288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1001288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_set_flags: 1002288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1003288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @flags: 1004288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1005288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1006288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1007288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1008288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 1009f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodvoid 10100c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbodhb_buffer_set_flags (hb_buffer_t *buffer, 10110c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod hb_buffer_flags_t flags) 10120c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod{ 10130c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod if (unlikely (hb_object_is_inert (buffer))) 10140c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod return; 10150c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod 10160c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod buffer->flags = flags; 10170c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod} 10180c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod 1019288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1020288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_get_flags: 1021288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1022288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1023288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1024288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1025288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 1026288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1027288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1028288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 10290c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbodhb_buffer_flags_t 10300c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbodhb_buffer_get_flags (hb_buffer_t *buffer) 10310c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod{ 10320c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod return buffer->flags; 10330c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod} 10340c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod 10355ebabecef382c3e8b0a2a5657b2c01f7ff37d796Behdad Esfahbod 1036288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1037288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_reset: 1038288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1039288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1040288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1041288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1042288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1043288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 10447a26864308bd1ca8d5f47d798411cac7239b7d38Behdad Esfahbodvoid 1045c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbodhb_buffer_reset (hb_buffer_t *buffer) 1046c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod{ 1047468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod buffer->reset (); 10487a26864308bd1ca8d5f47d798411cac7239b7d38Behdad Esfahbod} 10497a26864308bd1ca8d5f47d798411cac7239b7d38Behdad Esfahbod 1050288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1051288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_clear_contents: 1052288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1053288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1054288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1055288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1056288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1057288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 105882ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbodvoid 10591172dc736280566426eb6dade1a886b2a0ca9aa4Behdad Esfahbodhb_buffer_clear_contents (hb_buffer_t *buffer) 106082ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod{ 106182ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod buffer->clear (); 106282ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod} 106382ecaff736e245e117d70b6ec1497508c6eb08d2Behdad Esfahbod 1064288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1065288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_pre_allocate: 1066288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1067288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @size: 1068288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1069288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1070288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1071288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 1072288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1073288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1074288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 1075a6a79df5fe2ed2cd307e7a991346faee164e70d9Behdad Esfahbodhb_bool_t 107602a534b23f2d1e7475109563b9f61221ed020e8bRyan Lortiehb_buffer_pre_allocate (hb_buffer_t *buffer, unsigned int size) 1077f9cd1014f8f4d0394b5e0e9eefc1e2af13c59cabBehdad Esfahbod{ 1078468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod return buffer->ensure (size); 1079f9cd1014f8f4d0394b5e0e9eefc1e2af13c59cabBehdad Esfahbod} 1080f9cd1014f8f4d0394b5e0e9eefc1e2af13c59cabBehdad Esfahbod 1081288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1082288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_allocation_successful: 1083288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1084288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1085288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1086288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1087288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 1088288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1089288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1090288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 1091aab0de50e23727b69fa8c3d4e05c50c114c62835Behdad Esfahbodhb_bool_t 1092aab0de50e23727b69fa8c3d4e05c50c114c62835Behdad Esfahbodhb_buffer_allocation_successful (hb_buffer_t *buffer) 1093aab0de50e23727b69fa8c3d4e05c50c114c62835Behdad Esfahbod{ 1094aab0de50e23727b69fa8c3d4e05c50c114c62835Behdad Esfahbod return !buffer->in_error; 1095aab0de50e23727b69fa8c3d4e05c50c114c62835Behdad Esfahbod} 1096aab0de50e23727b69fa8c3d4e05c50c114c62835Behdad Esfahbod 1097288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1098288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_add: 1099288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1100288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @codepoint: 1101288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @cluster: 1102288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1103288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1104288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1105288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1106288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 1107f9cd1014f8f4d0394b5e0e9eefc1e2af13c59cabBehdad Esfahbodvoid 1108f85faee9b3cb841ea977403945e2c877ab32b97aBehdad Esfahbodhb_buffer_add (hb_buffer_t *buffer, 1109f85faee9b3cb841ea977403945e2c877ab32b97aBehdad Esfahbod hb_codepoint_t codepoint, 1110f85faee9b3cb841ea977403945e2c877ab32b97aBehdad Esfahbod unsigned int cluster) 11116b347138b597c41af24453f630336ba2fc033dc5Behdad Esfahbod{ 111266ac2ff32e24f0d5658ca172147613081a133847Behdad Esfahbod buffer->add (codepoint, cluster); 111305207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod buffer->clear_context (1); 11149111b21ef99d5e53348176f683261b0101eb427fBehdad Esfahbod} 11159111b21ef99d5e53348176f683261b0101eb427fBehdad Esfahbod 1116288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1117288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_set_length: 1118288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1119288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @length: 1120288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1121288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1122288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1123288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Return value: 1124288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1125288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1126288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 1127c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbodhb_bool_t 1128c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbodhb_buffer_set_length (hb_buffer_t *buffer, 1129c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod unsigned int length) 1130c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod{ 1131e1ac38f8dd04c29d2d4140f5a492cdaf25d72901Behdad Esfahbod if (unlikely (hb_object_is_inert (buffer))) 1132e1ac38f8dd04c29d2d4140f5a492cdaf25d72901Behdad Esfahbod return length == 0; 1133e1ac38f8dd04c29d2d4140f5a492cdaf25d72901Behdad Esfahbod 1134468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod if (!buffer->ensure (length)) 11350594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return false; 1136c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod 1137c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod /* Wipe the new space */ 1138c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod if (length > buffer->len) { 1139c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod memset (buffer->info + buffer->len, 0, sizeof (buffer->info[0]) * (length - buffer->len)); 1140c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod if (buffer->have_positions) 1141c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod memset (buffer->pos + buffer->len, 0, sizeof (buffer->pos[0]) * (length - buffer->len)); 1142c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod } 1143c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod 1144c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod buffer->len = length; 114505207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod 114605207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod if (!length) 114705207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod buffer->clear_context (0); 114805207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod buffer->clear_context (1); 114905207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod 11500594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return true; 1151c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod} 1152c910bec863215f918c659f58debbc7fe5264d7b6Behdad Esfahbod 11535f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod/** 11545f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * hb_buffer_get_length: 11555f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * @buffer: a buffer. 11565f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 11575f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Returns the number of items in the buffer. 11585f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 11595f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Return value: buffer length. 11605f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 11615f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Since: 1.0 1162c44b81833d5bfb9a926d348a76463314c3ec2018Behdad Esfahbod **/ 116311fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbodunsigned int 11643d14528b8b2e7da425a9df7057fc9fb326d8298cBehdad Esfahbodhb_buffer_get_length (hb_buffer_t *buffer) 116511fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod{ 11666960350be97f24e97140391025b56369c393a3dfBehdad Esfahbod return buffer->len; 116711fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod} 116811fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod 11695f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod/** 11705f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * hb_buffer_get_glyph_infos: 11715f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * @buffer: a buffer. 11725f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * @length: (out): output array length. 11735f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 11745f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Returns buffer glyph information array. Returned pointer 11755f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * is valid as long as buffer contents are not modified. 11765f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 11775f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Return value: (transfer none) (array length=length): buffer glyph information array. 11785f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 11795f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Since: 1.0 1180c44b81833d5bfb9a926d348a76463314c3ec2018Behdad Esfahbod **/ 118111fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbodhb_glyph_info_t * 118270566befc59cfa8b9c43ac682749c40ea783b1ddRyan Lortiehb_buffer_get_glyph_infos (hb_buffer_t *buffer, 118370566befc59cfa8b9c43ac682749c40ea783b1ddRyan Lortie unsigned int *length) 118411fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod{ 118570566befc59cfa8b9c43ac682749c40ea783b1ddRyan Lortie if (length) 118670566befc59cfa8b9c43ac682749c40ea783b1ddRyan Lortie *length = buffer->len; 118770566befc59cfa8b9c43ac682749c40ea783b1ddRyan Lortie 11887e7007a1c9bf2c07a8369752126ece8fa6164248Behdad Esfahbod return (hb_glyph_info_t *) buffer->info; 118911fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod} 119011fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod 11915f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod/** 11925f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * hb_buffer_get_glyph_positions: 11935f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * @buffer: a buffer. 11945f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * @length: (out): output length. 11955f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 11965f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Returns buffer glyph position array. Returned pointer 11975f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * is valid as long as buffer contents are not modified. 11985f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 11995f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Return value: (transfer none) (array length=length): buffer glyph position array. 12005f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 12015f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Since: 1.0 1202c44b81833d5bfb9a926d348a76463314c3ec2018Behdad Esfahbod **/ 120311fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbodhb_glyph_position_t * 120470566befc59cfa8b9c43ac682749c40ea783b1ddRyan Lortiehb_buffer_get_glyph_positions (hb_buffer_t *buffer, 120570566befc59cfa8b9c43ac682749c40ea783b1ddRyan Lortie unsigned int *length) 120611fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod{ 1207314905d7548d5be58354546d660754b807b6efb2Behdad Esfahbod if (!buffer->have_positions) 1208468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod buffer->clear_positions (); 120911fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod 121070566befc59cfa8b9c43ac682749c40ea783b1ddRyan Lortie if (length) 121170566befc59cfa8b9c43ac682749c40ea783b1ddRyan Lortie *length = buffer->len; 121270566befc59cfa8b9c43ac682749c40ea783b1ddRyan Lortie 12131b621823f3e31b48c80cc8b0691dfa873ba086cdBehdad Esfahbod return (hb_glyph_position_t *) buffer->pos; 121411fbb5487d9900a019440ef8235f35c9f525decbBehdad Esfahbod} 1215fbaf8ffa098bd2b6fb4f4bc2d04b360a319c4af5Behdad Esfahbod 12165f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod/** 12175f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * hb_buffer_reverse: 12185f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * @buffer: a buffer. 12195f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 12205f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Reverses buffer contents. 12215f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 12225f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Since: 1.0 1223c44b81833d5bfb9a926d348a76463314c3ec2018Behdad Esfahbod **/ 1224ff44f88df2c46920f3ec2384ef321a4c7bb0f6efBehdad Esfahbodvoid 1225ff44f88df2c46920f3ec2384ef321a4c7bb0f6efBehdad Esfahbodhb_buffer_reverse (hb_buffer_t *buffer) 1226ff44f88df2c46920f3ec2384ef321a4c7bb0f6efBehdad Esfahbod{ 1227468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod buffer->reverse (); 1228ff44f88df2c46920f3ec2384ef321a4c7bb0f6efBehdad Esfahbod} 1229ff44f88df2c46920f3ec2384ef321a4c7bb0f6efBehdad Esfahbod 12305f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod/** 12315f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * hb_buffer_reverse_clusters: 12325f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * @buffer: a buffer. 12335f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 12345f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Reverses buffer clusters. That is, the buffer contents are 12355f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * reversed, then each cluster (consecutive items having the 12365f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * same cluster number) are reversed again. 12375f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 12385f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Since: 1.0 1239c44b81833d5bfb9a926d348a76463314c3ec2018Behdad Esfahbod **/ 1240ff44f88df2c46920f3ec2384ef321a4c7bb0f6efBehdad Esfahbodvoid 1241ff44f88df2c46920f3ec2384ef321a4c7bb0f6efBehdad Esfahbodhb_buffer_reverse_clusters (hb_buffer_t *buffer) 1242ff44f88df2c46920f3ec2384ef321a4c7bb0f6efBehdad Esfahbod{ 1243468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod buffer->reverse_clusters (); 1244ff44f88df2c46920f3ec2384ef321a4c7bb0f6efBehdad Esfahbod} 1245ff44f88df2c46920f3ec2384ef321a4c7bb0f6efBehdad Esfahbod 12465f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod/** 12475f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * hb_buffer_guess_segment_properties: 12485f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * @buffer: a buffer. 12495f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 12505f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Sets unset buffer segment properties based on buffer Unicode 12515f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * contents. If buffer is not empty, it must have content type 12525f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * %HB_BUFFER_CONTENT_TYPE_UNICODE. 12535f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 12545f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * If buffer script is not set (ie. is %HB_SCRIPT_INVALID), it 12555f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * will be set to the Unicode script of the first character in 12565f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * the buffer that has a script other than %HB_SCRIPT_COMMON, 12575f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * %HB_SCRIPT_INHERITED, and %HB_SCRIPT_UNKNOWN. 12585f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 12595f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Next, if buffer direction is not set (ie. is %HB_DIRECTION_INVALID), 12605f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * it will be set to the natural horizontal direction of the 12615f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * buffer script as returned by hb_script_get_horizontal_direction(). 12625f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 12635f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Finally, if buffer language is not set (ie. is %HB_LANGUAGE_INVALID), 12645f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * it will be set to the process's default language as returned by 12655f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * hb_language_get_default(). This may change in the future by 12665f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * taking buffer script into consideration when choosing a language. 12675f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * 12685f512017ba615ba6ac8e5da2ea0c57a72db2c26bBehdad Esfahbod * Since: 1.0 1269c44b81833d5bfb9a926d348a76463314c3ec2018Behdad Esfahbod **/ 127002aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbodvoid 12713f82f8ff07a9d16a7c047129658c1bbedfdb5436Behdad Esfahbodhb_buffer_guess_segment_properties (hb_buffer_t *buffer) 127202aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod{ 12733f82f8ff07a9d16a7c047129658c1bbedfdb5436Behdad Esfahbod buffer->guess_segment_properties (); 127402aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod} 127502aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod 12767f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbodtemplate <typename T> 12777f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbodstatic inline void 12787f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbodhb_buffer_add_utf (hb_buffer_t *buffer, 12797f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod const T *text, 12807f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod int text_length, 12817f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod unsigned int item_offset, 12827f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod int item_length) 12837f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod{ 12847f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_UNICODE || 12857f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod (!buffer->len && buffer->content_type == HB_BUFFER_CONTENT_TYPE_INVALID)); 12867f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod 12877f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod if (unlikely (hb_object_is_inert (buffer))) 12887f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod return; 12897f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod 12901f66c3c1a0eb869c0d85a015235313177e0cec62Behdad Esfahbod if (text_length == -1) 12911f66c3c1a0eb869c0d85a015235313177e0cec62Behdad Esfahbod text_length = hb_utf_strlen (text); 12927f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod 12937f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod if (item_length == -1) 12947f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod item_length = text_length - item_offset; 12957f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod 12967f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod buffer->ensure (buffer->len + item_length * sizeof (T) / 4); 12977f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod 1298da70111ab234e8b740ce6fb1789a1809fbec0c44Behdad Esfahbod /* If buffer is empty and pre-context provided, install it. 1299da70111ab234e8b740ce6fb1789a1809fbec0c44Behdad Esfahbod * This check is written this way, to make sure people can 1300da70111ab234e8b740ce6fb1789a1809fbec0c44Behdad Esfahbod * provide pre-context in one add_utf() call, then provide 1301da70111ab234e8b740ce6fb1789a1809fbec0c44Behdad Esfahbod * text in a follow-up call. See: 1302da70111ab234e8b740ce6fb1789a1809fbec0c44Behdad Esfahbod * 1303da70111ab234e8b740ce6fb1789a1809fbec0c44Behdad Esfahbod * https://bugzilla.mozilla.org/show_bug.cgi?id=801410#c13 1304da70111ab234e8b740ce6fb1789a1809fbec0c44Behdad Esfahbod */ 1305da70111ab234e8b740ce6fb1789a1809fbec0c44Behdad Esfahbod if (!buffer->len && item_offset > 0) 130605207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod { 130705207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod /* Add pre-context */ 130805207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod buffer->clear_context (0); 130905207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod const T *prev = text + item_offset; 131005207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod const T *start = text; 131105207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod while (start < prev && buffer->context_len[0] < buffer->CONTEXT_LENGTH) 131205207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod { 131305207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod hb_codepoint_t u; 131405207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod prev = hb_utf_prev (prev, start, &u); 131505207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod buffer->context[0][buffer->context_len[0]++] = u; 131605207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod } 131705207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod } 131805207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod 131905207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod const T *next = text + item_offset; 13207f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod const T *end = next + item_length; 132105207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod while (next < end) 132205207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod { 13237f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod hb_codepoint_t u; 13247f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod const T *old_next = next; 13257f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod next = hb_utf_next (next, end, &u); 132666ac2ff32e24f0d5658ca172147613081a133847Behdad Esfahbod buffer->add (u, old_next - (const T *) text); 132705207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod } 132805207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod 132905207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod /* Add post-context */ 133005207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod buffer->clear_context (1); 133105207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod end = text + text_length; 133205207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod while (next < end && buffer->context_len[1] < buffer->CONTEXT_LENGTH) 133305207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod { 133405207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod hb_codepoint_t u; 133505207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod next = hb_utf_next (next, end, &u); 133605207a79e0ae1769c5feaebe3fd99bdf9cfcf834Behdad Esfahbod buffer->context[1][buffer->context_len[1]++] = u; 13377f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod } 13387f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod 13397f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod buffer->content_type = HB_BUFFER_CONTENT_TYPE_UNICODE; 1340299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod} 1341299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod 1342288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1343288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_add_utf8: 1344288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1345288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @text: (array length=text_length): 1346288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @text_length: 1347288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @item_offset: 1348288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @item_length: 1349288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1350288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1351288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1352288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1353288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 1354299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbodvoid 1355299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbodhb_buffer_add_utf8 (hb_buffer_t *buffer, 1356299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod const char *text, 1357944b2ba1ce076385f985212bbdf2df96a8a995f0Behdad Esfahbod int text_length, 1358299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod unsigned int item_offset, 1359944b2ba1ce076385f985212bbdf2df96a8a995f0Behdad Esfahbod int item_length) 1360299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod{ 13617f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod hb_buffer_add_utf (buffer, (const uint8_t *) text, text_length, item_offset, item_length); 1362299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod} 1363299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod 1364288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1365288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_add_utf16: 1366288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1367288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @text: (array length=text_length): 1368288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @text_length: 1369288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @item_offset: 1370288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @item_length: 1371288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1372288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1373288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1374288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1375288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 1376299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbodvoid 1377299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbodhb_buffer_add_utf16 (hb_buffer_t *buffer, 1378299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod const uint16_t *text, 1379944b2ba1ce076385f985212bbdf2df96a8a995f0Behdad Esfahbod int text_length, 1380299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod unsigned int item_offset, 1381288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod int item_length) 1382299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod{ 13837f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod hb_buffer_add_utf (buffer, text, text_length, item_offset, item_length); 13840e0a4da9b7677a09e00d27313236e1f333864dd6Behdad Esfahbod} 13850e0a4da9b7677a09e00d27313236e1f333864dd6Behdad Esfahbod 1386288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1387288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_add_utf32: 1388288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1389288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @text: (array length=text_length): 1390288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @text_length: 1391288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @item_offset: 1392288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @item_length: 1393288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1394288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1395288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1396288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1397288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 1398299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbodvoid 1399299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbodhb_buffer_add_utf32 (hb_buffer_t *buffer, 1400299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod const uint32_t *text, 1401944b2ba1ce076385f985212bbdf2df96a8a995f0Behdad Esfahbod int text_length, 1402299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod unsigned int item_offset, 1403944b2ba1ce076385f985212bbdf2df96a8a995f0Behdad Esfahbod int item_length) 1404299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod{ 14057f19ae7b9f806a2e35206b2ad41651c5f80b2537Behdad Esfahbod hb_buffer_add_utf (buffer, text, text_length, item_offset, item_length); 1406299f08961ffcea27e8def4f0743d0c86ef8dadf1Behdad Esfahbod} 1407acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 1408acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 140939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbodstatic int 141039b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbodcompare_info_codepoint (const hb_glyph_info_t *pa, 141139b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod const hb_glyph_info_t *pb) 141239b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod{ 141339b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod return (int) pb->codepoint - (int) pa->codepoint; 141439b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod} 141539b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 141639b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbodstatic inline void 141739b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbodnormalize_glyphs_cluster (hb_buffer_t *buffer, 141839b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod unsigned int start, 141939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod unsigned int end, 142039b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod bool backward) 142139b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod{ 142239b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod hb_glyph_position_t *pos = buffer->pos; 142339b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 142439b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod /* Total cluster advance */ 142539b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod hb_position_t total_x_advance = 0, total_y_advance = 0; 142639b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod for (unsigned int i = start; i < end; i++) 142739b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod { 142839b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod total_x_advance += pos[i].x_advance; 142939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod total_y_advance += pos[i].y_advance; 143039b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod } 143139b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 143239b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod hb_position_t x_advance = 0, y_advance = 0; 143339b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod for (unsigned int i = start; i < end; i++) 143439b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod { 143539b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod pos[i].x_offset += x_advance; 143639b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod pos[i].y_offset += y_advance; 143739b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 143839b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod x_advance += pos[i].x_advance; 143939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod y_advance += pos[i].y_advance; 144039b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 144139b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod pos[i].x_advance = 0; 144239b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod pos[i].y_advance = 0; 144339b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod } 144439b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 144539b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod if (backward) 144639b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod { 144739b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod /* Transfer all cluster advance to the last glyph. */ 144839b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod pos[end - 1].x_advance = total_x_advance; 144939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod pos[end - 1].y_advance = total_y_advance; 145039b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 145139b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod hb_bubble_sort (buffer->info + start, end - start - 1, compare_info_codepoint, buffer->pos + start); 145239b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod } else { 145339b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod /* Transfer all cluster advance to the first glyph. */ 145439b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod pos[start].x_advance += total_x_advance; 145539b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod pos[start].y_advance += total_y_advance; 145639b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod for (unsigned int i = start + 1; i < end; i++) { 145739b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod pos[i].x_offset -= total_x_advance; 145839b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod pos[i].y_offset -= total_y_advance; 145939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod } 146039b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod hb_bubble_sort (buffer->info + start + 1, end - start - 1, compare_info_codepoint, buffer->pos + start + 1); 146139b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod } 146239b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod} 146339b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 1464288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod/** 1465288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * hb_buffer_normalize_glyphs: 1466288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * @buffer: a buffer. 1467288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1468288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1469288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * 1470288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod * Since: 1.0 1471288f2899979bcc9e68f8115cb76e3271ed0e17bcBehdad Esfahbod **/ 147239b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbodvoid 147339b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbodhb_buffer_normalize_glyphs (hb_buffer_t *buffer) 147439b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod{ 147539b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod assert (buffer->have_positions); 14767d37280600c157f3c4eae8746e99511702a58e8fBehdad Esfahbod assert (buffer->content_type == HB_BUFFER_CONTENT_TYPE_GLYPHS); 147739b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 147839b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction); 147939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 148039b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod unsigned int count = buffer->len; 148139b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod if (unlikely (!count)) return; 148239b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod hb_glyph_info_t *info = buffer->info; 148339b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod 148439b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod unsigned int start = 0; 148539b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod unsigned int end; 148639b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod for (end = start + 1; end < count; end++) 148739b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod if (info[start].cluster != info[end].cluster) { 148839b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod normalize_glyphs_cluster (buffer, start, end, backward); 148939b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod start = end; 149039b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod } 149139b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod normalize_glyphs_cluster (buffer, start, end, backward); 149239b17837b4064d59c18cebb49c1c0b5b8cc0c117Behdad Esfahbod} 1493