mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-25 08:51:07 +01:00
[util] Use hb_face_create_from_file_or_fail()
This commit is contained in:
1 parent
12fc715dd6
commit
aa933abb76
4 files changed
+18
-44
No files matched your search
+9
-20
@@ -48,12 +48,10 @@ struct face_options_t
|
||||
~cache_t ()
|
||||
{
|
||||
g_free (font_path);
|
||||
hb_blob_destroy (blob);
|
||||
hb_face_destroy (face);
|
||||
}
|
||||
|
||||
char *font_path = nullptr;
|
||||
hb_blob_t *blob = nullptr;
|
||||
unsigned face_index = (unsigned) -1;
|
||||
hb_face_t *face = nullptr;
|
||||
} cache;
|
||||
@@ -61,7 +59,6 @@ struct face_options_t
|
||||
char *font_file = nullptr;
|
||||
unsigned face_index = 0;
|
||||
|
||||
hb_blob_t *blob = nullptr;
|
||||
hb_face_t *face = nullptr;
|
||||
};
|
||||
|
||||
@@ -92,34 +89,26 @@ face_options_t::post_parse (GError **error)
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!cache.font_path || 0 != strcmp (cache.font_path, font_path))
|
||||
if (!cache.font_path ||
|
||||
0 != strcmp (cache.font_path, font_path) ||
|
||||
cache.face_index != face_index)
|
||||
{
|
||||
hb_blob_destroy (cache.blob);
|
||||
cache.blob = hb_blob_create_from_file_or_fail (font_path);
|
||||
hb_face_destroy (cache.face);
|
||||
cache.face = hb_face_create_from_file_or_fail (font_path,
|
||||
face_index);
|
||||
cache.face_index = face_index;
|
||||
|
||||
free ((char *) cache.font_path);
|
||||
cache.font_path = g_strdup (font_path);
|
||||
|
||||
if (!cache.blob)
|
||||
if (!cache.face)
|
||||
{
|
||||
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
|
||||
"%s: Failed reading file", font_path);
|
||||
"%s: Failed loading font face", font_path);
|
||||
return;
|
||||
}
|
||||
|
||||
hb_face_destroy (cache.face);
|
||||
cache.face = nullptr;
|
||||
cache.face_index = (unsigned) -1;
|
||||
}
|
||||
|
||||
if (cache.face_index != face_index)
|
||||
{
|
||||
hb_face_destroy (cache.face);
|
||||
cache.face = hb_face_create (cache.blob, face_index);
|
||||
cache.face_index = face_index;
|
||||
}
|
||||
|
||||
blob = cache.blob;
|
||||
face = cache.face;
|
||||
}
|
||||
|
||||
|
||||
@@ -349,7 +349,9 @@ struct info_t :
|
||||
void
|
||||
_show_face_count ()
|
||||
{
|
||||
hb_blob_t *blob = hb_face_reference_table (face, HB_TAG_NONE);
|
||||
printf ("Face count: %u\n", hb_face_count (blob));
|
||||
hb_blob_destroy (blob);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
+5
-19
@@ -43,13 +43,6 @@ void free_ft_library ()
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
_release_blob (void *arg)
|
||||
{
|
||||
FT_Face ft_face = (FT_Face) arg;
|
||||
hb_blob_destroy ((hb_blob_t *) ft_face->generic.data);
|
||||
}
|
||||
|
||||
static inline cairo_font_face_t *
|
||||
helper_cairo_create_ft_font_face (const font_options_t *font_opts)
|
||||
{
|
||||
@@ -68,15 +61,11 @@ helper_cairo_create_ft_font_face (const font_options_t *font_opts)
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned int blob_length;
|
||||
const char *blob_data = hb_blob_get_data (font_opts->blob, &blob_length);
|
||||
|
||||
if (FT_New_Memory_Face (ft_library,
|
||||
(const FT_Byte *) blob_data,
|
||||
blob_length,
|
||||
font_opts->face_index,
|
||||
&ft_face))
|
||||
fail (false, "FT_New_Memory_Face fail");
|
||||
if (FT_New_Face (ft_library,
|
||||
font_opts->font_file,
|
||||
font_opts->face_index,
|
||||
&ft_face))
|
||||
fail (false, "FT_New_Face fail");
|
||||
}
|
||||
if (!ft_face)
|
||||
{
|
||||
@@ -87,9 +76,6 @@ helper_cairo_create_ft_font_face (const font_options_t *font_opts)
|
||||
}
|
||||
else
|
||||
{
|
||||
ft_face->generic.data = hb_blob_reference (font_opts->blob);
|
||||
ft_face->generic.finalizer = _release_blob;
|
||||
|
||||
#if !defined(HB_NO_VAR) && defined(HAVE_FT_SET_VAR_BLEND_COORDINATES)
|
||||
unsigned int num_coords;
|
||||
const float *coords = hb_font_get_var_coords_design (font_opts->font, &num_coords);
|
||||
|
||||
@@ -7,11 +7,8 @@
|
||||
static
|
||||
hb_face_t* open_font(const char* path)
|
||||
{
|
||||
hb_blob_t *blob = hb_blob_create_from_file_or_fail (path);
|
||||
g_assert(blob);
|
||||
hb_face_t* face = hb_face_create(blob, 0);
|
||||
hb_blob_destroy(blob);
|
||||
|
||||
hb_face_t *face = hb_face_create_from_file_or_fail (path, 0);
|
||||
g_assert (face);
|
||||
return face;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user