changeset 23018:a4517aa83565

Add outline glyph cache (unused yet).
author eugeni
date Fri, 20 Apr 2007 23:04:21 +0000
parents f3b04984b0da
children 4934af4fdd0f
files libass/ass_cache.c libass/ass_cache.h
diffstat 2 files changed, 68 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libass/ass_cache.c	Fri Apr 20 23:02:20 2007 +0000
+++ b/libass/ass_cache.c	Fri Apr 20 23:04:21 2007 +0000
@@ -265,3 +265,49 @@
 	ass_bitmap_cache_init();
 }
 
+//---------------------------------
+// glyph cache
+
+hashmap_t* glyph_cache;
+
+static void glyph_hash_dtor(void* key, size_t key_size, void* value, size_t value_size)
+{
+	glyph_hash_val_t* v = value;
+	if (v->glyph) FT_Done_Glyph(v->glyph);
+	free(key);
+	free(value);
+}
+
+void cache_add_glyph(glyph_hash_key_t* key, glyph_hash_val_t* val)
+{
+	hashmap_insert(glyph_cache, key, val);
+}
+
+/**
+ * \brief Get a glyph from glyph cache.
+ * \param key hash key
+ * \return requested hash val or 0 if not found
+*/ 
+glyph_hash_val_t* cache_find_glyph(glyph_hash_key_t* key)
+{
+	return hashmap_find(glyph_cache, key);
+}
+
+void ass_glyph_cache_init(void)
+{
+	glyph_cache = hashmap_init(sizeof(glyph_hash_key_t),
+				   sizeof(glyph_hash_val_t),
+				   0xFFFF + 13,
+				   glyph_hash_dtor, NULL, NULL);
+}
+
+void ass_glyph_cache_done(void)
+{
+	hashmap_done(glyph_cache);
+}
+
+void ass_glyph_cache_reset(void)
+{
+	ass_glyph_cache_done();
+	ass_glyph_cache_init();
+}
--- a/libass/ass_cache.h	Fri Apr 20 23:02:20 2007 +0000
+++ b/libass/ass_cache.h	Fri Apr 20 23:04:21 2007 +0000
@@ -57,6 +57,28 @@
 void ass_bitmap_cache_reset(void);
 void ass_bitmap_cache_done(void);
 
+// describes an outline glyph
+typedef struct glyph_hash_key_s {
+	ass_font_t* font;
+	int size; // font size
+	uint32_t ch; // character code
+	int bold, italic;
+	unsigned scale_x, scale_y; // 16.16
+	FT_Vector advance; // subpixel shift vector
+} glyph_hash_key_t;
+
+typedef struct glyph_hash_val_s {
+	FT_Glyph glyph;
+	FT_BBox bbox_scaled; // bbox after scaling, but before rotation
+	FT_Vector advance; // 26.6, advance distance to the next bitmap in line
+} glyph_hash_val_t;
+
+void ass_glyph_cache_init(void);
+void cache_add_glyph(glyph_hash_key_t* key, glyph_hash_val_t* val);
+glyph_hash_val_t* cache_find_glyph(glyph_hash_key_t* key);
+void ass_glyph_cache_reset(void);
+void ass_glyph_cache_done(void);
+
 typedef struct hashmap_s hashmap_t; 
 typedef void (*hashmap_item_dtor_t)(void* key, size_t key_size, void* value, size_t value_size);
 typedef int (*hashmap_key_compare_t)(void* key1, void* key2, size_t key_size);