Implement nil font functions

This commit is contained in:
Behdad Esfahbod 2009-11-03 20:27:05 -05:00
parent 8fb3d1aa4e
commit 7951279b4a
7 changed files with 91 additions and 26 deletions

1
TODO
View File

@ -1,6 +1,7 @@
- cmap14 support in get_glyph callback
- Use size_t in sanitize?
- Buffer error handling?
- Better define HB_INTERNAL
hb-ot:
- Fix ot query APIs

View File

@ -44,10 +44,10 @@ struct _hb_font_funcs_t {
hb_bool_t immutable;
hb_font_get_glyph_func_t glyph_func;
hb_font_get_contour_point_func_t contour_point_func;
hb_font_get_glyph_metrics_func_t glyph_metrics_func;
hb_font_get_kerning_func_t kerning_func;
hb_font_get_glyph_func_t get_glyph;
hb_font_get_contour_point_func_t get_contour_point;
hb_font_get_glyph_metrics_func_t get_glyph_metrics;
hb_font_get_kerning_func_t get_kerning;
};
HB_INTERNAL hb_font_funcs_t

View File

@ -32,19 +32,43 @@
#include "hb-ot-layout-private.h"
#include <string.h>
/*
* hb_font_funcs_t
*/
static hb_codepoint_t
hb_font_get_glyph_nil (hb_font_t *font, hb_face_t *face, const void *user_data,
hb_codepoint_t unicode, hb_codepoint_t variant_selector)
{ return unicode; }
static hb_bool_t
hb_font_get_contour_point_nil (hb_font_t *font, hb_face_t *face, const void *user_data,
unsigned int point_index,
hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y)
{ return false; }
static void
hb_font_get_glyph_metrics_nil (hb_font_t *font, hb_face_t *face, const void *user_data,
hb_codepoint_t glyph, hb_glyph_metrics_t *metrics)
{ memset (metrics, 0, sizeof (*metrics)); }
static hb_position_t
hb_font_get_kerning_nil (hb_font_t *font, hb_face_t *face, const void *user_data,
hb_codepoint_t first_glyph, hb_codepoint_t second_glyph)
{ return 0; }
hb_font_funcs_t _hb_font_funcs_nil = {
HB_REFERENCE_COUNT_INVALID, /* ref_count */
TRUE, /* immutable */
NULL, /* glyph_func */
NULL, /* contour_point_func */
NULL, /* glyph_metrics_func */
NULL /* kerning_func */
hb_font_get_glyph_nil,
hb_font_get_contour_point_nil,
hb_font_get_glyph_metrics_nil,
hb_font_get_kerning_nil
};
hb_font_funcs_t *
@ -105,6 +129,46 @@ hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs)
}
void
hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
hb_font_get_glyph_func_t glyph_func)
{
if (ffuncs->immutable)
return;
ffuncs->get_glyph = glyph_func ? glyph_func : hb_font_get_glyph_nil;
}
void
hb_font_funcs_set_contour_point_func (hb_font_funcs_t *ffuncs,
hb_font_get_contour_point_func_t contour_point_func)
{
if (ffuncs->immutable)
return;
ffuncs->get_contour_point = contour_point_func ? contour_point_func : hb_font_get_contour_point_nil;
}
void
hb_font_funcs_set_glyph_metrics_func (hb_font_funcs_t *ffuncs,
hb_font_get_glyph_metrics_func_t glyph_metrics_func)
{
if (ffuncs->immutable)
return;
ffuncs->get_glyph_metrics = glyph_metrics_func ? glyph_metrics_func : hb_font_get_glyph_metrics_nil;
}
void
hb_font_funcs_set_kerning_func (hb_font_funcs_t *ffuncs,
hb_font_get_kerning_func_t kerning_func)
{
if (ffuncs->immutable)
return;
ffuncs->get_kerning = kerning_func ? kerning_func : hb_font_get_kerning_nil;
}
/*
* hb_face_t

View File

@ -92,16 +92,15 @@ hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
/* funcs */
typedef struct _hb_glyph_metrics_t hb_glyph_metrics_t;
struct _hb_glyph_metrics_t
typedef struct _hb_glyph_metrics_t
{
hb_position_t x_pos;
hb_position_t y_pos;
hb_position_t x_advance;
hb_position_t y_advance;
hb_position_t x_offset;
hb_position_t y_offset;
hb_position_t width;
hb_position_t height;
};
} hb_glyph_metrics_t;
typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
hb_codepoint_t unicode, hb_codepoint_t variant_selector);

View File

@ -176,7 +176,8 @@ struct AnchorFormat2
inline void get_anchor (hb_ot_layout_context_t *context, hb_codepoint_t glyph_id,
hb_position_t *x, hb_position_t *y) const
{
/* TODO Contour */
/* TODO Contour
* NOTE only adjust directions with nonzero ppem */
*x = _hb_16dot16_mul_trunc (context->font->x_scale, xCoordinate);
*y = _hb_16dot16_mul_trunc (context->font->y_scale, yCoordinate);
}
@ -856,12 +857,12 @@ struct CursivePosFormat1
if (buffer->direction == HB_DIRECTION_RTL)
{
POSITION (buffer->in_pos)->x_advance = entry_x - gpi->anchor_x;
POSITION (buffer->in_pos)->new_advance = TRUE;
POSITION (buffer->in_pos)->new_advance = true;
}
else
{
POSITION (last_pos)->x_advance = gpi->anchor_x - entry_x;
POSITION (last_pos)->new_advance = TRUE;
POSITION (last_pos)->new_advance = true;
}
if (lookup_flag & LookupFlag::RightToLeft)

View File

@ -372,7 +372,7 @@ struct Ligature
}
if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_MARK))
is_mark = FALSE;
is_mark = false;
if (HB_LIKELY (IN_GLYPH (j) != component[i]))
return false;

View File

@ -151,15 +151,15 @@ typedef int hb_mutex_t;
ASSERT_STATIC (sizeof (_type) == (_size) + VAR * sizeof (_var_type1) + VAR * sizeof (_var_type2))
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define _HB_BOOLEAN_EXPR(expr) \
__extension__ ({ \
int _cairo_boolean_var_; \
if (expr) \
_cairo_boolean_var_ = 1; \
else \
_cairo_boolean_var_ = 0; \
_cairo_boolean_var_; \
})
#define _HB_BOOLEAN_EXPR(expr) \
__extension__ ({ \
int _hb_boolean_var_; \
if (expr) \
_hb_boolean_var_ = 1; \
else \
_hb_boolean_var_ = 0; \
_hb_boolean_var_; \
})
#define HB_LIKELY(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 1))
#define HB_UNLIKELY(expr) (__builtin_expect (_HB_BOOLEAN_EXPR(expr), 0))
#else