gfx/harfbuzz/src/hb-fallback-shape.cc

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /*
michael@0 2 * Copyright © 2011 Google, Inc.
michael@0 3 *
michael@0 4 * This is part of HarfBuzz, a text shaping library.
michael@0 5 *
michael@0 6 * Permission is hereby granted, without written agreement and without
michael@0 7 * license or royalty fees, to use, copy, modify, and distribute this
michael@0 8 * software and its documentation for any purpose, provided that the
michael@0 9 * above copyright notice and the following two paragraphs appear in
michael@0 10 * all copies of this software.
michael@0 11 *
michael@0 12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
michael@0 13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
michael@0 14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
michael@0 15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
michael@0 16 * DAMAGE.
michael@0 17 *
michael@0 18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
michael@0 19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
michael@0 20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
michael@0 21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
michael@0 22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
michael@0 23 *
michael@0 24 * Google Author(s): Behdad Esfahbod
michael@0 25 */
michael@0 26
michael@0 27 #define HB_SHAPER fallback
michael@0 28 #include "hb-shaper-impl-private.hh"
michael@0 29
michael@0 30
michael@0 31 /*
michael@0 32 * shaper face data
michael@0 33 */
michael@0 34
michael@0 35 struct hb_fallback_shaper_face_data_t {};
michael@0 36
michael@0 37 hb_fallback_shaper_face_data_t *
michael@0 38 _hb_fallback_shaper_face_data_create (hb_face_t *face HB_UNUSED)
michael@0 39 {
michael@0 40 return (hb_fallback_shaper_face_data_t *) HB_SHAPER_DATA_SUCCEEDED;
michael@0 41 }
michael@0 42
michael@0 43 void
michael@0 44 _hb_fallback_shaper_face_data_destroy (hb_fallback_shaper_face_data_t *data HB_UNUSED)
michael@0 45 {
michael@0 46 }
michael@0 47
michael@0 48
michael@0 49 /*
michael@0 50 * shaper font data
michael@0 51 */
michael@0 52
michael@0 53 struct hb_fallback_shaper_font_data_t {};
michael@0 54
michael@0 55 hb_fallback_shaper_font_data_t *
michael@0 56 _hb_fallback_shaper_font_data_create (hb_font_t *font HB_UNUSED)
michael@0 57 {
michael@0 58 return (hb_fallback_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
michael@0 59 }
michael@0 60
michael@0 61 void
michael@0 62 _hb_fallback_shaper_font_data_destroy (hb_fallback_shaper_font_data_t *data HB_UNUSED)
michael@0 63 {
michael@0 64 }
michael@0 65
michael@0 66
michael@0 67 /*
michael@0 68 * shaper shape_plan data
michael@0 69 */
michael@0 70
michael@0 71 struct hb_fallback_shaper_shape_plan_data_t {};
michael@0 72
michael@0 73 hb_fallback_shaper_shape_plan_data_t *
michael@0 74 _hb_fallback_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED,
michael@0 75 const hb_feature_t *user_features HB_UNUSED,
michael@0 76 unsigned int num_user_features HB_UNUSED)
michael@0 77 {
michael@0 78 return (hb_fallback_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED;
michael@0 79 }
michael@0 80
michael@0 81 void
michael@0 82 _hb_fallback_shaper_shape_plan_data_destroy (hb_fallback_shaper_shape_plan_data_t *data HB_UNUSED)
michael@0 83 {
michael@0 84 }
michael@0 85
michael@0 86
michael@0 87 /*
michael@0 88 * shaper
michael@0 89 */
michael@0 90
michael@0 91 hb_bool_t
michael@0 92 _hb_fallback_shape (hb_shape_plan_t *shape_plan HB_UNUSED,
michael@0 93 hb_font_t *font,
michael@0 94 hb_buffer_t *buffer,
michael@0 95 const hb_feature_t *features HB_UNUSED,
michael@0 96 unsigned int num_features HB_UNUSED)
michael@0 97 {
michael@0 98 /* TODO
michael@0 99 *
michael@0 100 * - Apply fallback kern.
michael@0 101 * - Handle Variation Selectors?
michael@0 102 * - Apply normalization?
michael@0 103 *
michael@0 104 * This will make the fallback shaper into a dumb "TrueType"
michael@0 105 * shaper which many people unfortunately still request.
michael@0 106 */
michael@0 107
michael@0 108 bool has_space;
michael@0 109 hb_codepoint_t space;
michael@0 110 has_space = font->get_glyph (' ', 0, &space);
michael@0 111
michael@0 112 buffer->clear_positions ();
michael@0 113
michael@0 114 unsigned int count = buffer->len;
michael@0 115
michael@0 116 for (unsigned int i = 0; i < count; i++)
michael@0 117 {
michael@0 118 if (has_space && buffer->unicode->is_default_ignorable (buffer->info[i].codepoint)) {
michael@0 119 buffer->info[i].codepoint = space;
michael@0 120 buffer->pos[i].x_advance = 0;
michael@0 121 buffer->pos[i].y_advance = 0;
michael@0 122 continue;
michael@0 123 }
michael@0 124 font->get_glyph (buffer->info[i].codepoint, 0, &buffer->info[i].codepoint);
michael@0 125 font->get_glyph_advance_for_direction (buffer->info[i].codepoint,
michael@0 126 buffer->props.direction,
michael@0 127 &buffer->pos[i].x_advance,
michael@0 128 &buffer->pos[i].y_advance);
michael@0 129 font->subtract_glyph_origin_for_direction (buffer->info[i].codepoint,
michael@0 130 buffer->props.direction,
michael@0 131 &buffer->pos[i].x_offset,
michael@0 132 &buffer->pos[i].y_offset);
michael@0 133 }
michael@0 134
michael@0 135 if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
michael@0 136 hb_buffer_reverse (buffer);
michael@0 137
michael@0 138 return true;
michael@0 139 }

mercurial