Fix reading fonts from stdin (#1060)
We were passing the font path directly to freetype so rendering was broken when we are getting the font from stdin. This fixes it by using FT_New_Memory_Face instead. This fixes: * build/util/hb-view /dev/stdin text < font.ttf * build/util/hb-view - text < font.ttf * cat font.ttf | build/util/hb-view - text but doesn't work on * cat font.ttf | build/util/hb-view /dev/stdin text which I will try to fix separately.
This commit is contained in:
parent
3654d9be6b
commit
aa0c5df419
|
@ -89,10 +89,16 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts)
|
||||||
atexit (free_ft_library);
|
atexit (free_ft_library);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
FT_New_Face (ft_library,
|
|
||||||
font_opts->font_file,
|
unsigned int blob_length;
|
||||||
font_opts->face_index,
|
const char *blob_data = hb_blob_get_data (font_opts->blob, &blob_length);
|
||||||
&ft_face);
|
|
||||||
|
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_face)
|
if (!ft_face)
|
||||||
{
|
{
|
||||||
|
|
|
@ -643,8 +643,6 @@ font_options_t::get_font (void) const
|
||||||
if (font)
|
if (font)
|
||||||
return font;
|
return font;
|
||||||
|
|
||||||
hb_blob_t *blob = nullptr;
|
|
||||||
|
|
||||||
/* Create the blob */
|
/* Create the blob */
|
||||||
if (!font_file)
|
if (!font_file)
|
||||||
fail (true, "No font file set");
|
fail (true, "No font file set");
|
||||||
|
@ -663,8 +661,9 @@ font_options_t::get_font (void) const
|
||||||
strerror (errno));
|
strerror (errno));
|
||||||
g_string_append_len (gs, buf, ret);
|
g_string_append_len (gs, buf, ret);
|
||||||
}
|
}
|
||||||
|
unsigned int len = gs->len;
|
||||||
char *font_data = g_string_free (gs, false);
|
char *font_data = g_string_free (gs, false);
|
||||||
blob = hb_blob_create (font_data, gs->len,
|
blob = hb_blob_create (font_data, len,
|
||||||
HB_MEMORY_MODE_WRITABLE, font_data,
|
HB_MEMORY_MODE_WRITABLE, font_data,
|
||||||
(hb_destroy_func_t) g_free);
|
(hb_destroy_func_t) g_free);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -455,6 +455,7 @@ struct font_options_t : option_group_t
|
||||||
font_size_x = font_size_y = default_font_size;
|
font_size_x = font_size_y = default_font_size;
|
||||||
font_funcs = nullptr;
|
font_funcs = nullptr;
|
||||||
|
|
||||||
|
blob = nullptr;
|
||||||
font = nullptr;
|
font = nullptr;
|
||||||
|
|
||||||
add_options (parser);
|
add_options (parser);
|
||||||
|
@ -471,6 +472,7 @@ struct font_options_t : option_group_t
|
||||||
hb_font_t *get_font (void) const;
|
hb_font_t *get_font (void) const;
|
||||||
|
|
||||||
char *font_file;
|
char *font_file;
|
||||||
|
mutable hb_blob_t *blob;
|
||||||
int face_index;
|
int face_index;
|
||||||
hb_variation_t *variations;
|
hb_variation_t *variations;
|
||||||
unsigned int num_variations;
|
unsigned int num_variations;
|
||||||
|
@ -483,7 +485,7 @@ struct font_options_t : option_group_t
|
||||||
mutable double font_size_y;
|
mutable double font_size_y;
|
||||||
char *font_funcs;
|
char *font_funcs;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable hb_font_t *font;
|
mutable hb_font_t *font;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue