struct _hb_font_t {
hb_object_header_t header;
+ hb_face_t *face;
+
unsigned int x_scale;
unsigned int y_scale;
static hb_codepoint_t
hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED,
- hb_face_t *face HB_UNUSED,
const void *user_data HB_UNUSED,
hb_codepoint_t unicode HB_UNUSED,
hb_codepoint_t variation_selector HB_UNUSED)
static void
hb_font_get_glyph_advance_nil (hb_font_t *font HB_UNUSED,
- hb_face_t *face HB_UNUSED,
const void *user_data HB_UNUSED,
hb_codepoint_t glyph HB_UNUSED,
hb_position_t *x_advance HB_UNUSED,
static void
hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
- hb_face_t *face HB_UNUSED,
const void *user_data HB_UNUSED,
hb_codepoint_t glyph HB_UNUSED,
hb_glyph_extents_t *extents HB_UNUSED)
static hb_bool_t
hb_font_get_contour_point_nil (hb_font_t *font HB_UNUSED,
- hb_face_t *face HB_UNUSED,
const void *user_data HB_UNUSED,
unsigned int point_index HB_UNUSED,
hb_codepoint_t glyph HB_UNUSED,
static hb_position_t
hb_font_get_kerning_nil (hb_font_t *font HB_UNUSED,
- hb_face_t *face HB_UNUSED,
const void *user_data HB_UNUSED,
hb_codepoint_t first_glyph HB_UNUSED,
hb_codepoint_t second_glyph HB_UNUSED)
hb_codepoint_t
-hb_font_get_glyph (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph (hb_font_t *font,
hb_codepoint_t unicode, hb_codepoint_t variation_selector)
{
- return font->klass->v.get_glyph (font, face, font->user_data,
+ return font->klass->v.get_glyph (font, font->user_data,
unicode, variation_selector);
}
void
-hb_font_get_glyph_advance (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph_advance (hb_font_t *font,
hb_codepoint_t glyph,
hb_position_t *x_advance, hb_position_t *y_advance)
{
*x_advance = *y_advance = 0;
- return font->klass->v.get_glyph_advance (font, face, font->user_data,
+ return font->klass->v.get_glyph_advance (font, font->user_data,
glyph, x_advance, y_advance);
}
void
-hb_font_get_glyph_extents (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph_extents (hb_font_t *font,
hb_codepoint_t glyph, hb_glyph_extents_t *extents)
{
memset (extents, 0, sizeof (*extents));
- return font->klass->v.get_glyph_extents (font, face, font->user_data,
+ return font->klass->v.get_glyph_extents (font, font->user_data,
glyph, extents);
}
hb_bool_t
-hb_font_get_contour_point (hb_font_t *font, hb_face_t *face,
+hb_font_get_contour_point (hb_font_t *font,
unsigned int point_index,
hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y)
{
*x = 0; *y = 0;
- return font->klass->v.get_contour_point (font, face, font->user_data,
+ return font->klass->v.get_contour_point (font, font->user_data,
point_index,
glyph, x, y);
}
hb_position_t
-hb_font_get_kerning (hb_font_t *font, hb_face_t *face,
+hb_font_get_kerning (hb_font_t *font,
hb_codepoint_t first_glyph, hb_codepoint_t second_glyph)
{
- return font->klass->v.get_kerning (font, face, font->user_data,
+ return font->klass->v.get_kerning (font, font->user_data,
first_glyph, second_glyph);
}
static hb_font_t _hb_font_nil = {
HB_OBJECT_HEADER_STATIC,
+ &_hb_face_nil,
+
0, /* x_scale */
0, /* y_scale */
};
hb_font_t *
-hb_font_create (void)
+hb_font_create (hb_face_t *face)
{
hb_font_t *font;
+ if (unlikely (!face))
+ face = &_hb_face_nil;
+ if (unlikely (hb_object_is_inert (face)))
+ return &_hb_font_nil;
if (!(font = hb_object_create<hb_font_t> ()))
return &_hb_font_nil;
+ font->face = hb_face_reference (face);
font->klass = &_hb_font_funcs_nil;
return font;
{
if (!hb_object_destroy (font)) return;
+ hb_face_destroy (font->face);
hb_font_funcs_destroy (font->klass);
if (font->destroy)
font->destroy (font->user_data);
}
+hb_face_t *
+hb_font_get_face (hb_font_t *font)
+{
+ return font->face;
+}
+
+
void
hb_font_set_funcs (hb_font_t *font,
hb_font_funcs_t *klass,
hb_position_t height;
} hb_glyph_extents_t;
-typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
+typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, const void *user_data,
hb_codepoint_t unicode, hb_codepoint_t variation_selector);
-typedef void (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
+typedef void (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, const void *user_data,
hb_codepoint_t glyph,
hb_position_t *x_advance, hb_position_t *y_advance);
-typedef void (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
+typedef void (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, const void *user_data,
hb_codepoint_t glyph,
hb_glyph_extents_t *extents);
-typedef hb_bool_t (*hb_font_get_contour_point_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
+typedef hb_bool_t (*hb_font_get_contour_point_func_t) (hb_font_t *font, const void *user_data,
unsigned int point_index, hb_codepoint_t glyph,
hb_position_t *x, hb_position_t *y);
-typedef hb_position_t (*hb_font_get_kerning_func_t) (hb_font_t *font, hb_face_t *face, const void *user_data,
+typedef hb_position_t (*hb_font_get_kerning_func_t) (hb_font_t *font, const void *user_data,
hb_codepoint_t first_glyph, hb_codepoint_t second_glyph);
hb_codepoint_t
-hb_font_get_glyph (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph (hb_font_t *font,
hb_codepoint_t unicode, hb_codepoint_t variation_selector);
void
-hb_font_get_glyph_advance (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph_advance (hb_font_t *font,
hb_codepoint_t glyph,
hb_position_t *x_advance, hb_position_t *y_advance);
void
-hb_font_get_glyph_extents (hb_font_t *font, hb_face_t *face,
+hb_font_get_glyph_extents (hb_font_t *font,
hb_codepoint_t glyph,
hb_glyph_extents_t *extents);
hb_bool_t
-hb_font_get_contour_point (hb_font_t *font, hb_face_t *face,
+hb_font_get_contour_point (hb_font_t *font,
unsigned int point_index, hb_codepoint_t glyph,
hb_position_t *x, hb_position_t *y);
hb_position_t
-hb_font_get_kerning (hb_font_t *font, hb_face_t *face,
+hb_font_get_kerning (hb_font_t *font,
hb_codepoint_t first_glyph, hb_codepoint_t second_glyph);
/* Fonts are very light-weight objects */
hb_font_t *
-hb_font_create (void);
+hb_font_create (hb_face_t *face);
hb_font_t *
hb_font_reference (hb_font_t *font);
hb_user_data_key_t *key);
+hb_face_t *
+hb_font_get_face (hb_font_t *font);
+
+
void
hb_font_set_funcs (hb_font_t *font,
hb_font_funcs_t *klass,
static hb_codepoint_t
hb_ft_get_glyph (hb_font_t *font HB_UNUSED,
- hb_face_t *face HB_UNUSED,
const void *user_data,
hb_codepoint_t unicode,
hb_codepoint_t variation_selector)
static void
hb_ft_get_glyph_advance (hb_font_t *font HB_UNUSED,
- hb_face_t *face HB_UNUSED,
const void *user_data,
hb_codepoint_t glyph,
hb_position_t *x_advance,
static void
hb_ft_get_glyph_extents (hb_font_t *font HB_UNUSED,
- hb_face_t *face HB_UNUSED,
const void *user_data,
hb_codepoint_t glyph,
hb_glyph_extents_t *extents)
static hb_bool_t
hb_ft_get_contour_point (hb_font_t *font HB_UNUSED,
- hb_face_t *face HB_UNUSED,
const void *user_data,
unsigned int point_index,
hb_codepoint_t glyph,
static hb_position_t
hb_ft_get_kerning (hb_font_t *font HB_UNUSED,
- hb_face_t *face HB_UNUSED,
const void *user_data,
hb_codepoint_t first_glyph,
hb_codepoint_t second_glyph)
{
hb_font_t *font;
- font = hb_font_create ();
+ font = hb_font_create (hb_ft_face_create_cached (ft_face));
hb_font_set_funcs (font,
hb_ft_get_font_funcs (),
ft_face, destroy);
inline int get_caret_value (hb_ot_layout_context_t *c, hb_direction_t direction, hb_codepoint_t glyph_id) const
{
hb_position_t x, y;
- if (hb_font_get_contour_point (c->font, c->face, caretValuePoint, glyph_id, &x, &y))
+ if (hb_font_get_contour_point (c->font, caretValuePoint, glyph_id, &x, &y))
return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;
else
return 0;
hb_bool_t ret = false;
if (x_ppem || y_ppem)
- ret = hb_font_get_contour_point (layout->font, layout->face, anchorPoint, glyph_id, &cx, &cy);
+ ret = hb_font_get_contour_point (layout->font, anchorPoint, glyph_id, &cx, &cy);
*x = x_ppem && ret ? cx : layout->scale_x (xCoordinate);
*y = y_ppem && ret ? cy : layout->scale_y (yCoordinate);
}
unsigned int
hb_ot_layout_get_ligature_carets (hb_font_t *font,
- hb_face_t *face,
hb_direction_t direction,
hb_codepoint_t glyph,
unsigned int start_offset,
{
hb_ot_layout_context_t c;
c.font = font;
- c.face = face;
- return _get_gdef (face).get_lig_carets (&c, direction, glyph, start_offset, caret_count, caret_array);
+ c.face = font->face;
+ return _get_gdef (c.face).get_lig_carets (&c, direction, glyph, start_offset, caret_count, caret_array);
}
/*
hb_bool_t
hb_ot_layout_position_lookup (hb_font_t *font,
- hb_face_t *face,
hb_buffer_t *buffer,
unsigned int lookup_index,
hb_mask_t mask)
{
hb_ot_layout_context_t c;
c.font = font;
- c.face = face;
- return _get_gpos (face).position_lookup (&c, buffer, lookup_index, mask);
+ c.face = font->face;
+ return _get_gpos (c.face).position_lookup (&c, buffer, lookup_index, mask);
}
void
/* Ligature caret positions */
unsigned int
hb_ot_layout_get_ligature_carets (hb_font_t *font,
- hb_face_t *face,
hb_direction_t direction,
hb_codepoint_t glyph,
unsigned int start_offset,
hb_bool_t
hb_ot_layout_position_lookup (hb_font_t *font,
- hb_face_t *face,
hb_buffer_t *buffer,
unsigned int lookup_index,
hb_mask_t mask);
inline void position (hb_font_t *font, hb_face_t *face, hb_buffer_t *buffer) const {
for (unsigned int i = 0; i < lookup_count[1]; i++)
- hb_ot_layout_position_lookup (font, face, buffer, lookup_maps[1][i].index, lookup_maps[1][i].mask);
+ hb_ot_layout_position_lookup (font, buffer, lookup_maps[1][i].index, lookup_maps[1][i].mask);
}
private:
#include "hb-ot-shape-private.hh"
#include "hb-ot-shape-complex-private.hh"
+#include "hb-font-private.hh"
+
HB_BEGIN_DECLS
static void
hb_map_glyphs (hb_font_t *font,
- hb_face_t *face,
hb_buffer_t *buffer)
{
if (unlikely (!buffer->len))
unsigned int count = buffer->len - 1;
for (buffer->i = 0; buffer->i < count;) {
if (unlikely (is_variation_selector (buffer->info[buffer->i + 1].codepoint))) {
- buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, buffer->info[buffer->i + 1].codepoint));
+ buffer->replace_glyph (hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, buffer->info[buffer->i + 1].codepoint));
buffer->i++;
} else {
- buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, 0));
+ buffer->replace_glyph (hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, 0));
}
}
if (likely (buffer->i < buffer->len))
- buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, 0));
+ buffer->replace_glyph (hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, 0));
buffer->swap ();
}
static void
hb_substitute_default (hb_ot_shape_context_t *c)
{
- hb_map_glyphs (c->font, c->face, c->buffer);
+ hb_map_glyphs (c->font, c->buffer);
}
static void
unsigned int count = c->buffer->len;
for (unsigned int i = 0; i < count; i++) {
- hb_font_get_glyph_advance (c->font, c->face, c->buffer->info[i].codepoint,
+ hb_font_get_glyph_advance (c->font, c->buffer->info[i].codepoint,
&c->buffer->pos[i].x_advance,
&c->buffer->pos[i].y_advance);
}
unsigned int count = c->buffer->len;
for (unsigned int i = 1; i < count; i++) {
hb_position_t kern, kern1, kern2;
- kern = hb_font_get_kerning (c->font, c->face, c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint);
+ kern = hb_font_get_kerning (c->font, c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint);
kern1 = kern >> 1;
kern2 = kern - kern1;
c->buffer->pos[i - 1].x_advance += kern1;
void
hb_ot_shape_execute (hb_ot_shape_plan_t *plan,
hb_font_t *font,
- hb_face_t *face,
hb_buffer_t *buffer,
const hb_feature_t *user_features,
unsigned int num_user_features)
{
- hb_ot_shape_context_t c = {plan, font, face, buffer, user_features, num_user_features};
+ hb_ot_shape_context_t c = {plan, font, font->face, buffer, user_features, num_user_features};
hb_ot_shape_execute_internal (&c);
}
void
hb_ot_shape (hb_font_t *font,
- hb_face_t *face,
hb_buffer_t *buffer,
const hb_feature_t *features,
unsigned int num_features)
{
hb_ot_shape_plan_t plan;
- hb_ot_shape_plan_internal (&plan, face, &buffer->props, features, num_features);
- hb_ot_shape_execute (&plan, font, face, buffer, features, num_features);
+ hb_ot_shape_plan_internal (&plan, font->face, &buffer->props, features, num_features);
+ hb_ot_shape_execute (&plan, font, buffer, features, num_features);
}
void
hb_ot_shape (hb_font_t *font,
- hb_face_t *face,
hb_buffer_t *buffer,
const hb_feature_t *features,
unsigned int num_features);
static void
hb_shape_internal (hb_font_t *font,
- hb_face_t *face,
hb_buffer_t *buffer,
const hb_feature_t *features,
unsigned int num_features)
{
-#if 0 && defined(HAVE_GRAPHITE)
- hb_blob_t *silf_blob;
- silf_blob = hb_face_reference_table (face, HB_GRAPHITE_TAG_Silf);
- if (hb_blob_get_length(silf_blob))
- {
- hb_graphite_shape(font, face, buffer, features, num_features);
- hb_blob_destroy(silf_blob);
- return;
- }
- hb_blob_destroy(silf_blob);
-#endif
-
- hb_ot_shape (font, face, buffer, features, num_features);
+ hb_ot_shape (font, buffer, features, num_features);
}
void
hb_shape (hb_font_t *font,
- hb_face_t *face,
hb_buffer_t *buffer,
const hb_feature_t *features,
unsigned int num_features)
//buffer->props.language = hb_language_get_default ();
}
- hb_shape_internal (font, face, buffer, features, num_features);
+ hb_shape_internal (font, buffer, features, num_features);
buffer->props = orig_props;
}
void
hb_shape (hb_font_t *font,
- hb_face_t *face,
hb_buffer_t *buffer,
const hb_feature_t *features,
unsigned int num_features);
{
cairo_scaled_font_t *scaled_font = cairo_get_scaled_font (cr);
FT_Face ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
- hb_face_t *hb_face = hb_ft_face_create_cached (ft_face);
hb_font_t *hb_font = hb_ft_font_create (ft_face, NULL);
hb_buffer_t *hb_buffer;
cairo_glyph_t *cairo_glyphs;
len = strlen (text);
hb_buffer_add_utf8 (hb_buffer, text, len, 0, len);
- hb_shape (hb_font, hb_face, hb_buffer, features, num_features);
+ hb_shape (hb_font, hb_buffer, features, num_features);
num_glyphs = hb_buffer_get_length (hb_buffer);
hb_glyph = hb_buffer_get_glyph_infos (hb_buffer, NULL);
cairo_glyphs[i].x = x * (1./64);
hb_buffer_destroy (hb_buffer);
hb_font_destroy (hb_font);
- hb_face_destroy (hb_face);
cairo_ft_scaled_font_unlock_face (scaled_font);
if (pnum_glyphs)
static void *
create_font (void)
{
- return hb_font_create ();
+ hb_face_t *face = (hb_face_t *) create_face ();
+ hb_font_t *font = hb_font_create (face);
+ hb_face_destroy (face);
+ return font;
}
static void *
create_font_inert (void)
{
- return NULL;
+ return hb_font_create (create_face_inert ());
}
static void *