diff --git a/TODO b/TODO index efcee6a4a..17ee8b88f 100644 --- a/TODO +++ b/TODO @@ -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 diff --git a/src/hb-font-private.h b/src/hb-font-private.h index 3d695d7fe..4293b7e2d 100644 --- a/src/hb-font-private.h +++ b/src/hb-font-private.h @@ -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 diff --git a/src/hb-font.cc b/src/hb-font.cc index 3108f5250..ff9b67b8b 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -32,19 +32,43 @@ #include "hb-ot-layout-private.h" +#include + + /* * 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 diff --git a/src/hb-font.h b/src/hb-font.h index 153279ff9..aa47aed13 100644 --- a/src/hb-font.h +++ b/src/hb-font.h @@ -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); diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh index 5d9fd48e0..deea9b975 100644 --- a/src/hb-ot-layout-gpos-private.hh +++ b/src/hb-ot-layout-gpos-private.hh @@ -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) diff --git a/src/hb-ot-layout-gsub-private.hh b/src/hb-ot-layout-gsub-private.hh index dde1cf5ab..c240e86cf 100644 --- a/src/hb-ot-layout-gsub-private.hh +++ b/src/hb-ot-layout-gsub-private.hh @@ -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; diff --git a/src/hb-private.h b/src/hb-private.h index c9f2ae7a6..caa0a5c6c 100644 --- a/src/hb-private.h +++ b/src/hb-private.h @@ -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