/* * Copyright © 2011,2012 Google, Inc. * * This is part of HarfBuzz, a text shaping library. * * Permission is hereby granted, without written agreement and without * license or royalty fees, to use, copy, modify, and distribute this * software and its documentation for any purpose, provided that the * above copyright notice and the following two paragraphs appear in * all copies of this software. * * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * * Google Author(s): Behdad Esfahbod */ #include "hb.hh" #ifndef HB_NO_OT_SHAPE #include "hb-ot-shape-normalize.hh" #include "hb-ot-shaper.hh" #include "hb-ot-shape.hh" /* * HIGHLEVEL DESIGN: * * This file exports one main function: _hb_ot_shape_normalize(). * * This function closely reflects the Unicode Normalization Algorithm, * yet it's different. * * Each shaper specifies whether it prefers decomposed (NFD) or composed (NFC). * The logic however tries to use whatever the font can support. * * In general what happens is that: each grapheme is decomposed in a chain * of 1:2 decompositions, marks reordered, and then recomposed if desired, * so far it's like Unicode Normalization. However, the decomposition and * recomposition only happens if the font supports the resulting characters. * * The goals are: * * - Try to render all canonically equivalent strings similarly. To really * achieve this we have to always do the full decomposition and then * selectively recompose from there. It's kinda too expensive though, so * we skip some cases. For example, if composed is desired, we simply * don't touch 1-character clusters that are supported by the font, even * though their NFC may be different. * * - When a font has a precomposed character for a sequence but the 'ccmp' * feature in the font is not adequate, use the precomposed character * which typically has better mark positioning. * * - When a font does not support a combining mark, but supports it precomposed * with previous base, use that. This needs the itemizer to have this * knowledge too. We need to provide assistance to the itemizer. * * - When a font does not support a character but supports its canonical * decomposition, well, use the decomposition. * * - The shapers can customize the compose and decompose functions to * offload some of their requirements to the normalizer. For example, the * Indic shaper may want to disallow recomposing of two matras. */ static bool decompose_unicode (const hb_ot_shape_normalize_context_t *c, hb_codepoint_t ab, hb_codepoint_t *a, hb_codepoint_t *b) { … } static bool compose_unicode (const hb_ot_shape_normalize_context_t *c, hb_codepoint_t a, hb_codepoint_t b, hb_codepoint_t *ab) { … } static inline void set_glyph (hb_glyph_info_t &info, hb_font_t *font) { … } static inline void output_char (hb_buffer_t *buffer, hb_codepoint_t unichar, hb_codepoint_t glyph) { … } static inline void next_char (hb_buffer_t *buffer, hb_codepoint_t glyph) { … } static inline void skip_char (hb_buffer_t *buffer) { … } /* Returns 0 if didn't decompose, number of resulting characters otherwise. */ static inline unsigned int decompose (const hb_ot_shape_normalize_context_t *c, bool shortest, hb_codepoint_t ab) { … } static inline void decompose_current_character (const hb_ot_shape_normalize_context_t *c, bool shortest) { … } static inline void handle_variation_selector_cluster (const hb_ot_shape_normalize_context_t *c, unsigned int end, bool short_circuit HB_UNUSED) { … } static inline void decompose_multi_char_cluster (const hb_ot_shape_normalize_context_t *c, unsigned int end, bool short_circuit) { … } static int compare_combining_class (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) { … } void _hb_ot_shape_normalize (const hb_ot_shape_plan_t *plan, hb_buffer_t *buffer, hb_font_t *font) { … } #endif