*/
#include "hb-private.hh"
+#include "hb-debug.hh"
#include "hb-ft.h"
#include "hb-font-private.hh"
-#include "hb-cache-private.hh" // Maybe use in the future?
-
#include FT_ADVANCES_H
#include FT_MULTIPLE_MASTERS_H
#include FT_TRUETYPE_TABLES_H
-
-#ifndef HB_DEBUG_FT
-#define HB_DEBUG_FT (HB_DEBUG+0)
-#endif
-
-
/* TODO:
*
* In general, this file does a fine job of what it's supposed to do.
*
* - In the future, we should add constructors to create fonts in font space?
*
- * - FT_Load_Glyph() is exteremely costly. Do something about it?
+ * - FT_Load_Glyph() is extremely costly. Do something about it?
*/
hb_ft_font_t *ft_font = (hb_ft_font_t *) calloc (1, sizeof (hb_ft_font_t));
if (unlikely (!ft_font))
- return NULL;
+ return nullptr;
ft_font->ft_face = ft_face;
ft_font->symbol = symbol;
}
static void
-_hb_ft_face_destroy (FT_Face ft_face)
+_hb_ft_face_destroy (void *data)
{
- FT_Done_Face (ft_face);
+ FT_Done_Face ((FT_Face) data);
}
static void
-_hb_ft_font_destroy (hb_ft_font_t *ft_font)
+_hb_ft_font_destroy (void *data)
{
+ hb_ft_font_t *ft_font = (hb_ft_font_t *) data;
+
if (ft_font->unref)
_hb_ft_face_destroy (ft_font->ft_face);
if (font->immutable)
return;
- if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)
+ if (font->destroy != _hb_ft_font_destroy)
return;
hb_ft_font_t *ft_font = (hb_ft_font_t *) font->user_data;
int
hb_ft_font_get_load_flags (hb_font_t *font)
{
- if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)
+ if (font->destroy != _hb_ft_font_destroy)
return 0;
const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font->user_data;
FT_Face
hb_ft_font_get_face (hb_font_t *font)
{
- if (font->destroy != (hb_destroy_func_t) _hb_ft_font_destroy)
- return NULL;
+ if (font->destroy != _hb_ft_font_destroy)
+ return nullptr;
const hb_ft_font_t *ft_font = (const hb_ft_font_t *) font->user_data;
return true;
}
-static hb_font_funcs_t *static_ft_funcs = NULL;
+static hb_font_funcs_t *static_ft_funcs = nullptr;
#ifdef HB_USE_ATEXIT
static
{
funcs = hb_font_funcs_create ();
- hb_font_funcs_set_font_h_extents_func (funcs, hb_ft_get_font_h_extents, NULL, NULL);
- //hb_font_funcs_set_font_v_extents_func (funcs, hb_ft_get_font_v_extents, NULL, NULL);
- hb_font_funcs_set_nominal_glyph_func (funcs, hb_ft_get_nominal_glyph, NULL, NULL);
- hb_font_funcs_set_variation_glyph_func (funcs, hb_ft_get_variation_glyph, NULL, NULL);
- hb_font_funcs_set_glyph_h_advance_func (funcs, hb_ft_get_glyph_h_advance, NULL, NULL);
- hb_font_funcs_set_glyph_v_advance_func (funcs, hb_ft_get_glyph_v_advance, NULL, NULL);
- //hb_font_funcs_set_glyph_h_origin_func (funcs, hb_ft_get_glyph_h_origin, NULL, NULL);
- hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ft_get_glyph_v_origin, NULL, NULL);
- hb_font_funcs_set_glyph_h_kerning_func (funcs, hb_ft_get_glyph_h_kerning, NULL, NULL);
- //hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_ft_get_glyph_v_kerning, NULL, NULL);
- hb_font_funcs_set_glyph_extents_func (funcs, hb_ft_get_glyph_extents, NULL, NULL);
- hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ft_get_glyph_contour_point, NULL, NULL);
- hb_font_funcs_set_glyph_name_func (funcs, hb_ft_get_glyph_name, NULL, NULL);
- hb_font_funcs_set_glyph_from_name_func (funcs, hb_ft_get_glyph_from_name, NULL, NULL);
+ hb_font_funcs_set_font_h_extents_func (funcs, hb_ft_get_font_h_extents, nullptr, nullptr);
+ //hb_font_funcs_set_font_v_extents_func (funcs, hb_ft_get_font_v_extents, nullptr, nullptr);
+ hb_font_funcs_set_nominal_glyph_func (funcs, hb_ft_get_nominal_glyph, nullptr, nullptr);
+ hb_font_funcs_set_variation_glyph_func (funcs, hb_ft_get_variation_glyph, nullptr, nullptr);
+ hb_font_funcs_set_glyph_h_advance_func (funcs, hb_ft_get_glyph_h_advance, nullptr, nullptr);
+ hb_font_funcs_set_glyph_v_advance_func (funcs, hb_ft_get_glyph_v_advance, nullptr, nullptr);
+ //hb_font_funcs_set_glyph_h_origin_func (funcs, hb_ft_get_glyph_h_origin, nullptr, nullptr);
+ hb_font_funcs_set_glyph_v_origin_func (funcs, hb_ft_get_glyph_v_origin, nullptr, nullptr);
+ hb_font_funcs_set_glyph_h_kerning_func (funcs, hb_ft_get_glyph_h_kerning, nullptr, nullptr);
+ //hb_font_funcs_set_glyph_v_kerning_func (funcs, hb_ft_get_glyph_v_kerning, nullptr, nullptr);
+ hb_font_funcs_set_glyph_extents_func (funcs, hb_ft_get_glyph_extents, nullptr, nullptr);
+ hb_font_funcs_set_glyph_contour_point_func (funcs, hb_ft_get_glyph_contour_point, nullptr, nullptr);
+ hb_font_funcs_set_glyph_name_func (funcs, hb_ft_get_glyph_name, nullptr, nullptr);
+ hb_font_funcs_set_glyph_from_name_func (funcs, hb_ft_get_glyph_from_name, nullptr, nullptr);
hb_font_funcs_make_immutable (funcs);
- if (!hb_atomic_ptr_cmpexch (&static_ft_funcs, NULL, funcs)) {
+ if (!hb_atomic_ptr_cmpexch (&static_ft_funcs, nullptr, funcs)) {
hb_font_funcs_destroy (funcs);
goto retry;
}
hb_font_set_funcs (font,
funcs,
_hb_ft_font_create (ft_face, symbol, unref),
- (hb_destroy_func_t) _hb_ft_font_destroy);
+ _hb_ft_font_destroy);
}
/* Note: FreeType like HarfBuzz uses the NONE tag for fetching the entire blob */
- error = FT_Load_Sfnt_Table (ft_face, tag, 0, NULL, &length);
+ error = FT_Load_Sfnt_Table (ft_face, tag, 0, nullptr, &length);
if (error)
- return NULL;
+ return nullptr;
buffer = (FT_Byte *) malloc (length);
- if (buffer == NULL)
- return NULL;
+ if (!buffer)
+ return nullptr;
error = FT_Load_Sfnt_Table (ft_face, tag, 0, buffer, &length);
if (error)
- return NULL;
+ return nullptr;
return hb_blob_create ((const char *) buffer, length,
HB_MEMORY_MODE_WRITABLE,
{
hb_face_t *face;
- if (ft_face->stream->read == NULL) {
+ if (!ft_face->stream->read) {
hb_blob_t *blob;
blob = hb_blob_create ((const char *) ft_face->stream->base,
hb_ft_face_create_referenced (FT_Face ft_face)
{
FT_Reference_Face (ft_face);
- return hb_ft_face_create (ft_face, (hb_destroy_func_t) _hb_ft_face_destroy);
+ return hb_ft_face_create (ft_face, _hb_ft_face_destroy);
}
static void
if (ft_face->generic.finalizer)
ft_face->generic.finalizer (ft_face);
- ft_face->generic.data = hb_ft_face_create (ft_face, NULL);
+ ft_face->generic.data = hb_ft_face_create (ft_face, nullptr);
ft_face->generic.finalizer = (FT_Generic_Finalizer) hb_ft_face_finalize;
}
font = hb_font_create (face);
hb_face_destroy (face);
_hb_ft_font_set_funcs (font, ft_face, false);
+ hb_ft_font_changed (font);
+ return font;
+}
+
+void
+hb_ft_font_changed (hb_font_t *font)
+{
+ if (font->destroy != _hb_ft_font_destroy)
+ return;
+
+ hb_ft_font_t *ft_font = (hb_ft_font_t *) font->user_data;
+ FT_Face ft_face = ft_font->ft_face;
+
hb_font_set_scale (font,
(int) (((uint64_t) ft_face->size->metrics.x_scale * (uint64_t) ft_face->units_per_EM + (1u<<15)) >> 16),
(int) (((uint64_t) ft_face->size->metrics.y_scale * (uint64_t) ft_face->units_per_EM + (1u<<15)) >> 16));
#endif
#ifdef HAVE_FT_GET_VAR_BLEND_COORDINATES
- FT_MM_Var *mm_var = NULL;
+ FT_MM_Var *mm_var = nullptr;
if (!FT_Get_MM_Var (ft_face, &mm_var))
{
FT_Fixed *ft_coords = (FT_Fixed *) calloc (mm_var->num_axis, sizeof (FT_Fixed));
{
if (!FT_Get_Var_Blend_Coordinates (ft_face, mm_var->num_axis, ft_coords))
{
+ bool nonzero = false;
+
for (unsigned int i = 0; i < mm_var->num_axis; ++i)
+ {
coords[i] = ft_coords[i] >>= 2;
+ nonzero = nonzero || coords[i];
+ }
- hb_font_set_var_coords_normalized (font, coords, mm_var->num_axis);
+ if (nonzero)
+ hb_font_set_var_coords_normalized (font, coords, mm_var->num_axis);
+ else
+ hb_font_set_var_coords_normalized (font, nullptr, 0);
}
- free (coords);
- free (ft_coords);
}
+ free (coords);
+ free (ft_coords);
+#ifdef HAVE_FT_DONE_MM_VAR
+ FT_Done_MM_Var (ft_face->glyph->library, mm_var);
+#else
free (mm_var);
+#endif
}
#endif
-
- return font;
}
/**
hb_ft_font_create_referenced (FT_Face ft_face)
{
FT_Reference_Face (ft_face);
- return hb_ft_font_create (ft_face, (hb_destroy_func_t) _hb_ft_face_destroy);
+ return hb_ft_font_create (ft_face, _hb_ft_face_destroy);
}
{
/* Not found; allocate one. */
if (FT_Init_FreeType (&library))
- return NULL;
+ return nullptr;
- if (!hb_atomic_ptr_cmpexch (&ft_library, NULL, library)) {
+ if (!hb_atomic_ptr_cmpexch (&ft_library, nullptr, library)) {
FT_Done_FreeType (library);
goto retry;
}
if (unlikely (!blob_length))
DEBUG_MSG (FT, font, "Font face has empty blob");
- FT_Face ft_face = NULL;
+ FT_Face ft_face = nullptr;
FT_Error err = FT_New_Memory_Face (get_ft_library (),
(const FT_Byte *) blob_data,
blob_length,
{
FT_Matrix matrix = { font->x_scale < 0 ? -1 : +1, 0,
0, font->y_scale < 0 ? -1 : +1};
- FT_Set_Transform (ft_face, &matrix, NULL);
+ FT_Set_Transform (ft_face, &matrix, nullptr);
}
+#ifdef HAVE_FT_SET_VAR_BLEND_COORDINATES
unsigned int num_coords;
const int *coords = hb_font_get_var_coords_normalized (font, &num_coords);
if (num_coords)
free (ft_coords);
}
}
+#endif
ft_face->generic.data = blob;
ft_face->generic.finalizer = (FT_Generic_Finalizer) _release_blob;