[util/hb-shape] Cache blob/face in batch mode
This commit is contained in:
parent
9a7ff54bb7
commit
ad03f34df7
|
@ -681,6 +681,10 @@ output_options_t::add_options (option_parser_t *parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char *font_options_t::cached_font_path = nullptr;
|
||||||
|
hb_blob_t *font_options_t::cached_blob = nullptr;
|
||||||
|
unsigned font_options_t::cached_face_index = (unsigned) -1;
|
||||||
|
hb_face_t *font_options_t::cached_face = nullptr;
|
||||||
|
|
||||||
hb_font_t *
|
hb_font_t *
|
||||||
font_options_t::get_font () const
|
font_options_t::get_font () const
|
||||||
|
@ -704,14 +708,39 @@ font_options_t::get_font () const
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
blob = hb_blob_create_from_file_or_fail (font_path);
|
if (cached_font_path && 0 == strcmp (cached_font_path, font_path))
|
||||||
|
blob = hb_blob_reference (cached_blob);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
blob = hb_blob_create_from_file_or_fail (font_path);
|
||||||
|
|
||||||
if (!blob)
|
if (!blob)
|
||||||
fail (false, "%s: Failed reading file", font_path);
|
fail (false, "%s: Failed reading file", font_path);
|
||||||
|
|
||||||
/* Create the face */
|
/* Update caches. */
|
||||||
hb_face_t *face = hb_face_create (blob, face_index);
|
|
||||||
hb_blob_destroy (blob);
|
hb_face_destroy (cached_face);
|
||||||
|
cached_face = nullptr;
|
||||||
|
cached_face_index = (unsigned) -1;
|
||||||
|
|
||||||
|
free ((char *) cached_font_path);
|
||||||
|
cached_font_path = strdup (font_path);
|
||||||
|
hb_blob_destroy (cached_blob);
|
||||||
|
cached_blob = hb_blob_reference (blob);
|
||||||
|
}
|
||||||
|
|
||||||
|
hb_face_t *face = nullptr;
|
||||||
|
if (cached_face_index == face_index)
|
||||||
|
face = hb_face_reference (cached_face);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
face = hb_face_create (blob, face_index);
|
||||||
|
hb_blob_destroy (blob);
|
||||||
|
|
||||||
|
cached_face_index = face_index;
|
||||||
|
hb_face_destroy (cached_face);
|
||||||
|
cached_face = hb_face_reference (face);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
font = hb_font_create (face);
|
font = hb_font_create (face);
|
||||||
|
|
|
@ -491,7 +491,7 @@ struct font_options_t : option_group_t
|
||||||
|
|
||||||
char *font_file;
|
char *font_file;
|
||||||
mutable hb_blob_t *blob;
|
mutable hb_blob_t *blob;
|
||||||
int face_index;
|
unsigned face_index;
|
||||||
hb_variation_t *variations;
|
hb_variation_t *variations;
|
||||||
unsigned int num_variations;
|
unsigned int num_variations;
|
||||||
int default_font_size;
|
int default_font_size;
|
||||||
|
@ -506,6 +506,11 @@ struct font_options_t : option_group_t
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable hb_font_t *font;
|
mutable hb_font_t *font;
|
||||||
|
|
||||||
|
static const char *cached_font_path;
|
||||||
|
static hb_blob_t *cached_blob;
|
||||||
|
static unsigned cached_face_index;
|
||||||
|
static hb_face_t *cached_face;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue