1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/harfbuzz/src/hb-fallback-shape.cc Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,139 @@ 1.4 +/* 1.5 + * Copyright © 2011 Google, Inc. 1.6 + * 1.7 + * This is part of HarfBuzz, a text shaping library. 1.8 + * 1.9 + * Permission is hereby granted, without written agreement and without 1.10 + * license or royalty fees, to use, copy, modify, and distribute this 1.11 + * software and its documentation for any purpose, provided that the 1.12 + * above copyright notice and the following two paragraphs appear in 1.13 + * all copies of this software. 1.14 + * 1.15 + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR 1.16 + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 1.17 + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN 1.18 + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 1.19 + * DAMAGE. 1.20 + * 1.21 + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, 1.22 + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 1.23 + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS 1.24 + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO 1.25 + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 1.26 + * 1.27 + * Google Author(s): Behdad Esfahbod 1.28 + */ 1.29 + 1.30 +#define HB_SHAPER fallback 1.31 +#include "hb-shaper-impl-private.hh" 1.32 + 1.33 + 1.34 +/* 1.35 + * shaper face data 1.36 + */ 1.37 + 1.38 +struct hb_fallback_shaper_face_data_t {}; 1.39 + 1.40 +hb_fallback_shaper_face_data_t * 1.41 +_hb_fallback_shaper_face_data_create (hb_face_t *face HB_UNUSED) 1.42 +{ 1.43 + return (hb_fallback_shaper_face_data_t *) HB_SHAPER_DATA_SUCCEEDED; 1.44 +} 1.45 + 1.46 +void 1.47 +_hb_fallback_shaper_face_data_destroy (hb_fallback_shaper_face_data_t *data HB_UNUSED) 1.48 +{ 1.49 +} 1.50 + 1.51 + 1.52 +/* 1.53 + * shaper font data 1.54 + */ 1.55 + 1.56 +struct hb_fallback_shaper_font_data_t {}; 1.57 + 1.58 +hb_fallback_shaper_font_data_t * 1.59 +_hb_fallback_shaper_font_data_create (hb_font_t *font HB_UNUSED) 1.60 +{ 1.61 + return (hb_fallback_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED; 1.62 +} 1.63 + 1.64 +void 1.65 +_hb_fallback_shaper_font_data_destroy (hb_fallback_shaper_font_data_t *data HB_UNUSED) 1.66 +{ 1.67 +} 1.68 + 1.69 + 1.70 +/* 1.71 + * shaper shape_plan data 1.72 + */ 1.73 + 1.74 +struct hb_fallback_shaper_shape_plan_data_t {}; 1.75 + 1.76 +hb_fallback_shaper_shape_plan_data_t * 1.77 +_hb_fallback_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan HB_UNUSED, 1.78 + const hb_feature_t *user_features HB_UNUSED, 1.79 + unsigned int num_user_features HB_UNUSED) 1.80 +{ 1.81 + return (hb_fallback_shaper_shape_plan_data_t *) HB_SHAPER_DATA_SUCCEEDED; 1.82 +} 1.83 + 1.84 +void 1.85 +_hb_fallback_shaper_shape_plan_data_destroy (hb_fallback_shaper_shape_plan_data_t *data HB_UNUSED) 1.86 +{ 1.87 +} 1.88 + 1.89 + 1.90 +/* 1.91 + * shaper 1.92 + */ 1.93 + 1.94 +hb_bool_t 1.95 +_hb_fallback_shape (hb_shape_plan_t *shape_plan HB_UNUSED, 1.96 + hb_font_t *font, 1.97 + hb_buffer_t *buffer, 1.98 + const hb_feature_t *features HB_UNUSED, 1.99 + unsigned int num_features HB_UNUSED) 1.100 +{ 1.101 + /* TODO 1.102 + * 1.103 + * - Apply fallback kern. 1.104 + * - Handle Variation Selectors? 1.105 + * - Apply normalization? 1.106 + * 1.107 + * This will make the fallback shaper into a dumb "TrueType" 1.108 + * shaper which many people unfortunately still request. 1.109 + */ 1.110 + 1.111 + bool has_space; 1.112 + hb_codepoint_t space; 1.113 + has_space = font->get_glyph (' ', 0, &space); 1.114 + 1.115 + buffer->clear_positions (); 1.116 + 1.117 + unsigned int count = buffer->len; 1.118 + 1.119 + for (unsigned int i = 0; i < count; i++) 1.120 + { 1.121 + if (has_space && buffer->unicode->is_default_ignorable (buffer->info[i].codepoint)) { 1.122 + buffer->info[i].codepoint = space; 1.123 + buffer->pos[i].x_advance = 0; 1.124 + buffer->pos[i].y_advance = 0; 1.125 + continue; 1.126 + } 1.127 + font->get_glyph (buffer->info[i].codepoint, 0, &buffer->info[i].codepoint); 1.128 + font->get_glyph_advance_for_direction (buffer->info[i].codepoint, 1.129 + buffer->props.direction, 1.130 + &buffer->pos[i].x_advance, 1.131 + &buffer->pos[i].y_advance); 1.132 + font->subtract_glyph_origin_for_direction (buffer->info[i].codepoint, 1.133 + buffer->props.direction, 1.134 + &buffer->pos[i].x_offset, 1.135 + &buffer->pos[i].y_offset); 1.136 + } 1.137 + 1.138 + if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction)) 1.139 + hb_buffer_reverse (buffer); 1.140 + 1.141 + return true; 1.142 +}