Hash :
02aeca98
Author :
Date :
2011-08-04T22:31:05
[API] Changes to main shape API hb_shape() now accepts a shaper_options and a shaper_list argument. Both can be set to NULL to emulate previous API. And in most situations they are expected to be set to NULL. hb_shape() also returns a boolean for now. If shaper_list is NULL, the return value can be ignored. shaper_options is ignored for now, but otherwise it should be a NULL-terminated list of strings. shaper_list is a NULL-terminated list of strings. Currently recognized strings are "ot" for native OpenType Layout implementation, "uniscribe" for the Uniscribe backend, and "fallback" for the non-complex backend (that will be implemented shortly). The fallback backend never fails. The env var HB_SHAPER_LIST is also parsed and honored. It's a colon-separated list of shaper names. The fallback shaper is invoked if none of the env-listed shapers succeed. New API hb_buffer_guess_properties() added.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
/*
* Copyright © 2011 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-test.h"
/* Unit tests for hb-shape.h */
/*
* This test provides a framework to test aspects of hb_shape() that are
* font-independent. Please add tests for any feature that fits that
* description.
*/
/* TODO Make this test data-driven and add some real test data */
/* TODO Test positions too. And test non-native direction. Test commit 2e18c6dbdfb */
static const char test_data[] = "test\0data";
static hb_position_t
glyph_h_advance_func (hb_font_t *font, void *font_data,
hb_codepoint_t glyph,
void *user_data)
{
switch (glyph) {
case 1: return 10;
case 2: return 6;
case 3: return 5;
}
return 0;
}
static hb_bool_t
glyph_func (hb_font_t *font, void *font_data,
hb_codepoint_t unicode, hb_codepoint_t variant_selector,
hb_codepoint_t *glyph,
void *user_data)
{
switch (unicode) {
case 'T': *glyph = 1; return TRUE;
case 'e': *glyph = 2; return TRUE;
case 's': *glyph = 3; return TRUE;
}
return FALSE;
}
static hb_position_t
glyph_h_kerning_func (hb_font_t *font, void *font_data,
hb_codepoint_t left, hb_codepoint_t right,
void *user_data)
{
if (left == 1 && right == 2)
return -2;
return 0;
}
static const char TesT[] = "TesT";
static void
test_shape (void)
{
hb_blob_t *blob;
hb_face_t *face;
hb_font_funcs_t *ffuncs;
hb_font_t *font;
hb_buffer_t *buffer;
unsigned int len;
hb_glyph_info_t *glyphs;
hb_glyph_position_t *positions;
blob = hb_blob_create (test_data, sizeof (test_data), HB_MEMORY_MODE_READONLY, NULL, NULL);
face = hb_face_create (blob, 0);
hb_blob_destroy (blob);
font = hb_font_create (face);
hb_face_destroy (face);
hb_font_set_scale (font, 10, 10);
ffuncs = hb_font_funcs_create ();
hb_font_funcs_set_glyph_h_advance_func (ffuncs, glyph_h_advance_func, NULL, NULL);
hb_font_funcs_set_glyph_func (ffuncs, glyph_func, NULL, NULL);
hb_font_funcs_set_glyph_h_kerning_func (ffuncs, glyph_h_kerning_func, NULL, NULL);
hb_font_set_funcs (font, ffuncs, NULL, NULL);
hb_font_funcs_destroy (ffuncs);
buffer = hb_buffer_create (0);
hb_buffer_set_direction (buffer, HB_DIRECTION_LTR);
hb_buffer_add_utf8 (buffer, TesT, 4, 0, 4);
hb_shape (font, buffer, NULL, 0, NULL, NULL);
len = hb_buffer_get_length (buffer);
glyphs = hb_buffer_get_glyph_infos (buffer, NULL);
positions = hb_buffer_get_glyph_positions (buffer, NULL);
{
const hb_codepoint_t output_glyphs[] = {1, 2, 3, 1};
const hb_position_t output_x_advances[] = {9, 5, 5, 10};
const hb_position_t output_x_offsets[] = {0, -1, 0, 0};
unsigned int i;
g_assert_cmpint (len, ==, 4);
for (i = 0; i < len; i++) {
g_assert_cmphex (glyphs[i].codepoint, ==, output_glyphs[i]);
g_assert_cmphex (glyphs[i].cluster, ==, i);
}
for (i = 0; i < len; i++) {
g_assert_cmpint (output_x_advances[i], ==, positions[i].x_advance);
g_assert_cmpint (output_x_offsets [i], ==, positions[i].x_offset);
g_assert_cmpint (0, ==, positions[i].y_advance);
g_assert_cmpint (0, ==, positions[i].y_offset);
}
}
hb_buffer_destroy (buffer);
hb_font_destroy (font);
}
int
main (int argc, char **argv)
{
hb_test_init (&argc, &argv);
hb_test_add (test_shape);
return hb_test_run();
}