hb-buffer-private.hh revision 468e9cb25c9bc14781b7013e447d763f93bf76a3
1a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod/* 22409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 1998-2004 David Turner and Werner Lemberg 32409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2004,2007,2009,2010 Red Hat, Inc. 4468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod * Copyright © 2011 Google, Inc. 56b347138b597c41af24453f630336ba2fc033dc5Behdad Esfahbod * 68f0d7e0c3fd4b05c43ac449be4f374dc2dc56127Behdad Esfahbod * This is part of HarfBuzz, a text shaping library. 76b347138b597c41af24453f630336ba2fc033dc5Behdad 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. 136b347138b597c41af24453f630336ba2fc033dc5Behdad 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 27468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod * Google Author(s): Behdad Esfahbod 286b347138b597c41af24453f630336ba2fc033dc5Behdad Esfahbod */ 29a2a9a023f6472ba262f89e5327318996b8258d25Behdad Esfahbod 30da8edbb62204dc39f93d500ef85929e234e0bd19Behdad Esfahbod#ifndef HB_BUFFER_PRIVATE_HH 31da8edbb62204dc39f93d500ef85929e234e0bd19Behdad Esfahbod#define HB_BUFFER_PRIVATE_HH 326b347138b597c41af24453f630336ba2fc033dc5Behdad Esfahbod 33c57d454accff66e5f2c58006e8fb40bc020b6182Behdad Esfahbod#include "hb-private.hh" 345c0adce1ccc739415c4b26ff13ffd2d77ea4bc6cBehdad Esfahbod#include "hb-buffer.h" 35fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod#include "hb-object-private.hh" 36fb194b8794898f51eb596fa4092c26606889d376Behdad Esfahbod#include "hb-unicode-private.hh" 376b347138b597c41af24453f630336ba2fc033dc5Behdad Esfahbod 38f96ffd43bce0ac6d9c897933c9be0e51d543e570Behdad EsfahbodHB_BEGIN_DECLS 396b347138b597c41af24453f630336ba2fc033dc5Behdad Esfahbod 40acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 4188474c6fdaf35c56368694a5b164f4988a004d49Behdad EsfahbodASSERT_STATIC (sizeof (hb_glyph_info_t) == 20); 42f1322e52d557726baa010be8d35a594748e8fa1aBehdad EsfahbodASSERT_STATIC (sizeof (hb_glyph_info_t) == sizeof (hb_glyph_position_t)); 43f1322e52d557726baa010be8d35a594748e8fa1aBehdad Esfahbod 44a7c5046d6b676a32298b97403a49235f7f255161Behdad Esfahbodtypedef struct _hb_segment_properties_t { 45a7c5046d6b676a32298b97403a49235f7f255161Behdad Esfahbod hb_direction_t direction; 46a7c5046d6b676a32298b97403a49235f7f255161Behdad Esfahbod hb_script_t script; 47a7c5046d6b676a32298b97403a49235f7f255161Behdad Esfahbod hb_language_t language; 48a7c5046d6b676a32298b97403a49235f7f255161Behdad Esfahbod} hb_segment_properties_t; 49a7c5046d6b676a32298b97403a49235f7f255161Behdad Esfahbod 50f1322e52d557726baa010be8d35a594748e8fa1aBehdad Esfahbod 51d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbodstruct _hb_buffer_t { 52fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod hb_object_header_t header; 53d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod 54d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod /* Information about how the text in the buffer should be treated */ 554e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod 56a7c5046d6b676a32298b97403a49235f7f255161Behdad Esfahbod hb_unicode_funcs_t *unicode; /* Unicode functions */ 57a7c5046d6b676a32298b97403a49235f7f255161Behdad Esfahbod hb_segment_properties_t props; /* Script, language, direction */ 58d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod 59d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod /* Buffer contents */ 60d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod 61e0db4b868f9fdd8e680890f87dd4e13a1c27b7a1Behdad Esfahbod bool in_error; /* Allocation failed */ 62fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod bool have_output; /* Whether we have an output buffer going on */ 63fca368c4682624346a0aaee690e1ad6ed4c0b337Behdad Esfahbod bool have_positions; /* Whether we have positions */ 64910a33fe8457a8e13f7eb77fc92fa59c31f5e8fdBehdad Esfahbod 65468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int idx; /* Cursor into ->info and ->pos arrays */ 66910a33fe8457a8e13f7eb77fc92fa59c31f5e8fdBehdad Esfahbod unsigned int len; /* Length of ->info and ->pos arrays */ 67cc1a8a938b4c13e76b58825a9e1951c4134e634aBehdad Esfahbod unsigned int out_len; /* Length of ->out array if have_output */ 68d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod 69c0af193c8e25c4f11d23b8893e9ce1c2d2615bb2Behdad Esfahbod unsigned int serial; 70c0af193c8e25c4f11d23b8893e9ce1c2d2615bb2Behdad Esfahbod 71c0af193c8e25c4f11d23b8893e9ce1c2d2615bb2Behdad Esfahbod unsigned int allocated; /* Length of allocated arrays */ 7288474c6fdaf35c56368694a5b164f4988a004d49Behdad Esfahbod hb_glyph_info_t *info; 7388474c6fdaf35c56368694a5b164f4988a004d49Behdad Esfahbod hb_glyph_info_t *out_info; 7488474c6fdaf35c56368694a5b164f4988a004d49Behdad Esfahbod hb_glyph_position_t *pos; 75d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod 76d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod 77d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod /* Methods */ 78468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 79468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void reset (void); 80468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 81cc1a8a938b4c13e76b58825a9e1951c4134e634aBehdad Esfahbod inline unsigned int backtrack_len (void) const 82468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod { return have_output? out_len : idx; } 83dbf56b1d94910f04823e53e39ace1e5145bddc04Behdad Esfahbod inline unsigned int next_serial (void) { return serial++; } 84468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 85468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void add (hb_codepoint_t codepoint, 86468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod hb_mask_t mask, 87468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int cluster); 88468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 89468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void reverse_range (unsigned int start, unsigned int end); 90468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void reverse (void); 91468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void reverse_clusters (void); 92468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 93468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void swap_buffers (void); 94468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void clear_output (void); 95468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void clear_positions (void); 96468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void replace_glyphs_be16 (unsigned int num_in, 97468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int num_out, 98468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod const uint16_t *glyph_data_be); 99468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void replace_glyph (hb_codepoint_t glyph_index); 100468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod /* Makes a copy of the glyph at idx to output and replace glyph_index */ 101468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void output_glyph (hb_codepoint_t glyph_index); 102468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod /* Copies glyph at idx to output but doesn't advance idx */ 103468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void copy_glyph (void); 104468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod /* Copies glyph at idx to output and advance idx. 105468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod * If there's no output, just advance idx. */ 106468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void next_glyph (void); 107468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod /* Advance idx without copying to output. */ 108468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod inline void skip_glyph (void) { idx++; } 1091ce7b87c4d8d1ab3ec1d5198351d71b7199f7c64Behdad Esfahbod 110bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod inline void reset_masks (hb_mask_t mask) 111bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod { 11231f18abecb149f8888a72510f2660328dd6de16dBehdad Esfahbod for (unsigned int j = 0; j < len; j++) 11331f18abecb149f8888a72510f2660328dd6de16dBehdad Esfahbod info[j].mask = mask; 114bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod } 115bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod inline void add_masks (hb_mask_t mask) 116bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod { 11731f18abecb149f8888a72510f2660328dd6de16dBehdad Esfahbod for (unsigned int j = 0; j < len; j++) 11831f18abecb149f8888a72510f2660328dd6de16dBehdad Esfahbod info[j].mask |= mask; 119bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod } 120468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL void set_masks (hb_mask_t value, 121468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod hb_mask_t mask, 122468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int cluster_start, 123468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod unsigned int cluster_end); 124468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 125468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod /* Internal methods */ 126468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL bool enlarge (unsigned int size); 127468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 128468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod inline bool ensure (unsigned int size) 129468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod { return likely (size <= allocated) ? TRUE : enlarge (size); } 130468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod 131468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod HB_INTERNAL bool make_room_for (unsigned int num_in, unsigned int num_out); 132d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod}; 133d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod 134d0316a81f59a4e814b0af78797d915d7ce04d119Behdad Esfahbod 135f96ffd43bce0ac6d9c897933c9be0e51d543e570Behdad EsfahbodHB_END_DECLS 1366b347138b597c41af24453f630336ba2fc033dc5Behdad Esfahbod 137da8edbb62204dc39f93d500ef85929e234e0bd19Behdad Esfahbod#endif /* HB_BUFFER_PRIVATE_HH */ 138