Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/font.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index f6ac43e65ac..76abedde770 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -66,6 +66,7 @@ struct cache_entry struct cache_key key; float advance; unsigned int has_contours : 1; + unsigned int has_advance : 1; };
static struct cache_entry * fontface_get_cache_entry(struct dwrite_fontface *fontface, const struct cache_key *key) @@ -97,9 +98,6 @@ static float fontface_get_glyph_advance(struct dwrite_fontface *fontface, float { if (!(entry = calloc(1, sizeof(*entry)))) return 0.0f; - - entry->advance = font_funcs->get_glyph_advance(fontface->get_font_object(fontface), fontsize, glyph, mode, &value); - entry->has_contours = !!value; entry->key = key;
size = fontface_get_cache_entry_size(entry); @@ -123,6 +121,13 @@ static float fontface_get_glyph_advance(struct dwrite_fontface *fontface, float fontface->cache.size += size; }
+ if (!entry->has_advance) + { + entry->advance = font_funcs->get_glyph_advance(fontface->get_font_object(fontface), fontsize, glyph, mode, &value); + entry->has_contours = !!value; + entry->has_advance = 1; + } + *has_contours = entry->has_contours; return entry->advance; }
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/dwrite_private.h | 7 +++---- dlls/dwrite/font.c | 12 +++++------- dlls/dwrite/freetype.c | 20 ++++++++++---------- dlls/dwrite/layout.c | 3 +-- 4 files changed, 19 insertions(+), 23 deletions(-)
diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index e0373dc2891..ba634c99917 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -444,7 +444,6 @@ extern HRESULT bidi_computelevels(const WCHAR*,UINT32,UINT8,UINT8*,UINT8*) DECLS
struct dwrite_glyphbitmap { - void *key; DWORD simulations; float emsize; BOOL nohint; @@ -735,8 +734,8 @@ struct font_backend_funcs UINT16 (CDECL *get_glyph_count)(font_object_handle object); INT32 (CDECL *get_glyph_advance)(font_object_handle object, float em_size, UINT16 glyph, DWRITE_MEASURING_MODE measuring_mode, BOOL *has_contours); - void (CDECL *get_glyph_bbox)(struct dwrite_glyphbitmap *bitmap_desc); - BOOL (CDECL *get_glyph_bitmap)(struct dwrite_glyphbitmap *bitmap_desc); + void (CDECL *get_glyph_bbox)(void *key, struct dwrite_glyphbitmap *bitmap_desc); + BOOL (CDECL *get_glyph_bitmap)(void *key, struct dwrite_glyphbitmap *bitmap_desc); void (CDECL *get_design_glyph_metrics)(font_object_handle object, UINT16 upem, UINT16 ascent, unsigned int simulations, UINT16 glyph, DWRITE_GLYPH_METRICS *metrics); }; @@ -744,4 +743,4 @@ struct font_backend_funcs extern void init_font_backend(void) DECLSPEC_HIDDEN; extern void release_font_backend(void) DECLSPEC_HIDDEN;
-extern void dwrite_fontface_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap) DECLSPEC_HIDDEN; +extern void dwrite_fontface_get_glyph_bbox(IDWriteFontFace *fontface, struct dwrite_glyphbitmap *bitmap) DECLSPEC_HIDDEN; diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 76abedde770..205b2f8c0f1 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -47,9 +47,9 @@ static const FLOAT RECOMMENDED_NATURAL_PPEM = 20.0f;
static const struct font_backend_funcs *font_funcs;
-void dwrite_fontface_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap) +void dwrite_fontface_get_glyph_bbox(IDWriteFontFace *fontface, struct dwrite_glyphbitmap *bitmap) { - font_funcs->get_glyph_bbox(bitmap); + font_funcs->get_glyph_bbox(fontface, bitmap); }
struct cache_key @@ -5836,7 +5836,6 @@ static void glyphrunanalysis_get_texturebounds(struct dwrite_glyphrunanalysis *a WARN("failed to get IDWriteFontFace4, 0x%08x\n", hr);
memset(&glyph_bitmap, 0, sizeof(glyph_bitmap)); - glyph_bitmap.key = fontface; glyph_bitmap.simulations = IDWriteFontFace4_GetSimulations(fontface); glyph_bitmap.emsize = analysis->run.fontEmSize; glyph_bitmap.nohint = is_natural_rendering_mode(analysis->rendering_mode); @@ -5848,7 +5847,7 @@ static void glyphrunanalysis_get_texturebounds(struct dwrite_glyphrunanalysis *a UINT32 bitmap_size;
glyph_bitmap.glyph = analysis->run.glyphIndices[i]; - font_funcs->get_glyph_bbox(&glyph_bitmap); + font_funcs->get_glyph_bbox(fontface, &glyph_bitmap);
bitmap_size = get_glyph_bitmap_pitch(analysis->rendering_mode, bbox->right - bbox->left) * (bbox->bottom - bbox->top); @@ -5927,7 +5926,6 @@ static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis) origin.x = origin.y = 0.0f;
memset(&glyph_bitmap, 0, sizeof(glyph_bitmap)); - glyph_bitmap.key = fontface; glyph_bitmap.simulations = IDWriteFontFace4_GetSimulations(fontface); glyph_bitmap.emsize = analysis->run.fontEmSize; glyph_bitmap.nohint = is_natural_rendering_mode(analysis->rendering_mode); @@ -5948,7 +5946,7 @@ static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis) BOOL is_1bpp;
glyph_bitmap.glyph = analysis->run.glyphIndices[i]; - font_funcs->get_glyph_bbox(&glyph_bitmap); + font_funcs->get_glyph_bbox(fontface, &glyph_bitmap);
if (IsRectEmpty(bbox)) continue; @@ -5958,7 +5956,7 @@ static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis)
glyph_bitmap.pitch = get_glyph_bitmap_pitch(analysis->rendering_mode, width); memset(src, 0, height * glyph_bitmap.pitch); - is_1bpp = font_funcs->get_glyph_bitmap(&glyph_bitmap); + is_1bpp = font_funcs->get_glyph_bitmap(fontface, &glyph_bitmap);
OffsetRect(bbox, analysis->origins[i].x, analysis->origins[i].y);
diff --git a/dlls/dwrite/freetype.c b/dlls/dwrite/freetype.c index a2304f264d5..dede7c46c9c 100644 --- a/dlls/dwrite/freetype.c +++ b/dlls/dwrite/freetype.c @@ -572,7 +572,7 @@ static BOOL is_face_scalable(void *key) return FALSE; }
-static BOOL get_glyph_transform(struct dwrite_glyphbitmap *bitmap, FT_Matrix *ret) +static BOOL get_glyph_transform(void *key, struct dwrite_glyphbitmap *bitmap, FT_Matrix *ret) { FT_Matrix m;
@@ -583,7 +583,7 @@ static BOOL get_glyph_transform(struct dwrite_glyphbitmap *bitmap, FT_Matrix *re
/* Some fonts provide mostly bitmaps and very few outlines, for example for .notdef. Disable transform if that's the case. */ - if (!is_face_scalable(bitmap->key) || (!bitmap->m && bitmap->simulations == 0)) + if (!is_face_scalable(key) || (!bitmap->m && !bitmap->simulations)) return FALSE;
if (bitmap->simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE) { @@ -602,7 +602,7 @@ static BOOL get_glyph_transform(struct dwrite_glyphbitmap *bitmap, FT_Matrix *re return TRUE; }
-static void CDECL freetype_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap) +static void CDECL freetype_get_glyph_bbox(void *key, struct dwrite_glyphbitmap *bitmap) { FTC_ImageTypeRec imagetype; FT_BBox bbox = { 0 }; @@ -612,9 +612,9 @@ static void CDECL freetype_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap)
RtlEnterCriticalSection(&freetype_cs);
- needs_transform = get_glyph_transform(bitmap, &m); + needs_transform = get_glyph_transform(key, bitmap, &m);
- imagetype.face_id = bitmap->key; + imagetype.face_id = key; imagetype.width = 0; imagetype.height = bitmap->emsize; imagetype.flags = needs_transform ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT; @@ -734,7 +734,7 @@ static BOOL freetype_get_aa_glyph_bitmap(struct dwrite_glyphbitmap *bitmap, FT_G return ret; }
-static BOOL CDECL freetype_get_glyph_bitmap(struct dwrite_glyphbitmap *bitmap) +static BOOL CDECL freetype_get_glyph_bitmap(void *key, struct dwrite_glyphbitmap *bitmap) { FTC_ImageTypeRec imagetype; BOOL needs_transform; @@ -744,9 +744,9 @@ static BOOL CDECL freetype_get_glyph_bitmap(struct dwrite_glyphbitmap *bitmap)
RtlEnterCriticalSection(&freetype_cs);
- needs_transform = get_glyph_transform(bitmap, &m); + needs_transform = get_glyph_transform(key, bitmap, &m);
- imagetype.face_id = bitmap->key; + imagetype.face_id = key; imagetype.width = 0; imagetype.height = bitmap->emsize; imagetype.flags = needs_transform ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT; @@ -865,12 +865,12 @@ static INT32 CDECL null_get_glyph_advance(font_object_handle object, float emsiz return 0; }
-static void CDECL null_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap) +static void CDECL null_get_glyph_bbox(void *key, struct dwrite_glyphbitmap *bitmap) { SetRectEmpty(&bitmap->bbox); }
-static BOOL CDECL null_get_glyph_bitmap(struct dwrite_glyphbitmap *bitmap) +static BOOL CDECL null_get_glyph_bitmap(void *key, struct dwrite_glyphbitmap *bitmap) { return FALSE; } diff --git a/dlls/dwrite/layout.c b/dlls/dwrite/layout.c index b2e71e7f436..b7ab855d1f1 100644 --- a/dlls/dwrite/layout.c +++ b/dlls/dwrite/layout.c @@ -3945,7 +3945,6 @@ static void layout_get_erun_bbox(struct dwrite_textlayout *layout, struct layout glyph_run.glyphOffsets = ®ular->run.glyphOffsets[start_glyph];
memset(&glyph_bitmap, 0, sizeof(glyph_bitmap)); - glyph_bitmap.key = glyph_run.fontFace; glyph_bitmap.simulations = IDWriteFontFace_GetSimulations(glyph_run.fontFace); glyph_bitmap.emsize = glyph_run.fontEmSize; glyph_bitmap.nohint = layout->measuringmode == DWRITE_MEASURING_MODE_NATURAL; @@ -3967,7 +3966,7 @@ static void layout_get_erun_bbox(struct dwrite_textlayout *layout, struct layout D2D1_RECT_F glyph_bbox;
glyph_bitmap.glyph = glyph_run.glyphIndices[i]; - dwrite_fontface_get_glyph_bbox(&glyph_bitmap); + dwrite_fontface_get_glyph_bbox(glyph_run.fontFace, &glyph_bitmap);
glyph_bbox.left = bbox->left; glyph_bbox.top = bbox->top;
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/dwrite_private.h | 2 +- dlls/dwrite/font.c | 96 +++++++++++++++++++++--------------- dlls/dwrite/freetype.c | 58 +++++++++++----------- 3 files changed, 88 insertions(+), 68 deletions(-)
diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index ba634c99917..b166766a167 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -734,7 +734,7 @@ struct font_backend_funcs UINT16 (CDECL *get_glyph_count)(font_object_handle object); INT32 (CDECL *get_glyph_advance)(font_object_handle object, float em_size, UINT16 glyph, DWRITE_MEASURING_MODE measuring_mode, BOOL *has_contours); - void (CDECL *get_glyph_bbox)(void *key, struct dwrite_glyphbitmap *bitmap_desc); + void (CDECL *get_glyph_bbox)(font_object_handle object, struct dwrite_glyphbitmap *bitmap_desc); BOOL (CDECL *get_glyph_bitmap)(void *key, struct dwrite_glyphbitmap *bitmap_desc); void (CDECL *get_design_glyph_metrics)(font_object_handle object, UINT16 upem, UINT16 ascent, unsigned int simulations, UINT16 glyph, DWRITE_GLYPH_METRICS *metrics); diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 205b2f8c0f1..c6ef61f7fe3 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -47,11 +47,6 @@ static const FLOAT RECOMMENDED_NATURAL_PPEM = 20.0f;
static const struct font_backend_funcs *font_funcs;
-void dwrite_fontface_get_glyph_bbox(IDWriteFontFace *fontface, struct dwrite_glyphbitmap *bitmap) -{ - font_funcs->get_glyph_bbox(fontface, bitmap); -} - struct cache_key { float size; @@ -65,40 +60,28 @@ struct cache_entry struct list mru; struct cache_key key; float advance; + RECT bbox; unsigned int has_contours : 1; unsigned int has_advance : 1; + unsigned int has_bbox : 1; };
-static struct cache_entry * fontface_get_cache_entry(struct dwrite_fontface *fontface, const struct cache_key *key) -{ - struct cache_entry *entry; - struct wine_rb_entry *e; - - if (!(e = wine_rb_get(&fontface->cache.tree, key))) return NULL; - entry = WINE_RB_ENTRY_VALUE(e, struct cache_entry, entry); - list_remove(&entry->mru); - list_add_head(&fontface->cache.mru, &entry->mru); - return WINE_RB_ENTRY_VALUE(entry, struct cache_entry, entry); -} - static size_t fontface_get_cache_entry_size(const struct cache_entry *entry) { return sizeof(*entry); }
-static float fontface_get_glyph_advance(struct dwrite_fontface *fontface, float fontsize, unsigned short glyph, - unsigned short mode, BOOL *has_contours) +static struct cache_entry * fontface_get_cache_entry(struct dwrite_fontface *fontface, const struct cache_key *key) { - struct cache_key key = { .size = fontsize, .glyph = glyph, .mode = mode }; struct cache_entry *entry, *old_entry; + struct wine_rb_entry *e; size_t size; - BOOL value;
- if (!(entry = fontface_get_cache_entry(fontface, &key))) + if (!(e = wine_rb_get(&fontface->cache.tree, key))) { - if (!(entry = calloc(1, sizeof(*entry)))) - return 0.0f; - entry->key = key; + if (!(entry = calloc(1, sizeof(*entry)))) return NULL; + entry->key = *key; + list_init(&entry->mru);
size = fontface_get_cache_entry_size(entry); if ((fontface->cache.size + size > fontface->cache.max_size) && !list_empty(&fontface->cache.mru)) @@ -110,16 +93,33 @@ static float fontface_get_glyph_advance(struct dwrite_fontface *fontface, float free(old_entry); }
- list_add_head(&fontface->cache.mru, &entry->mru); - if (wine_rb_put(&fontface->cache.tree, &key, &entry->entry) == -1) { WARN("Failed to add cache entry.\n"); - return 0.0f; + free(entry); + return NULL; }
fontface->cache.size += size; } + else + entry = WINE_RB_ENTRY_VALUE(e, struct cache_entry, entry); + + list_remove(&entry->mru); + list_add_head(&fontface->cache.mru, &entry->mru); + + return entry; +} + +static float fontface_get_glyph_advance(struct dwrite_fontface *fontface, float fontsize, unsigned short glyph, + unsigned short mode, BOOL *has_contours) +{ + struct cache_key key = { .size = fontsize, .glyph = glyph, .mode = mode }; + struct cache_entry *entry; + BOOL value; + + if (!(entry = fontface_get_cache_entry(fontface, &key))) + return 0.0f;
if (!entry->has_advance) { @@ -132,6 +132,32 @@ static float fontface_get_glyph_advance(struct dwrite_fontface *fontface, float return entry->advance; }
+void dwrite_fontface_get_glyph_bbox(IDWriteFontFace *iface, struct dwrite_glyphbitmap *bitmap) +{ + struct cache_key key = { .size = bitmap->emsize, .glyph = bitmap->glyph, .mode = DWRITE_MEASURING_MODE_NATURAL }; + struct dwrite_fontface *fontface = unsafe_impl_from_IDWriteFontFace(iface); + struct cache_entry *entry; + + EnterCriticalSection(&fontface->cs); + /* For now bypass cache for transformed cases. */ + if (bitmap->m && memcmp(bitmap->m, &identity, sizeof(*bitmap->m))) + { + font_funcs->get_glyph_bbox(fontface->get_font_object(fontface), bitmap); + } + else if ((entry = fontface_get_cache_entry(fontface, &key))) + { + if (entry->has_bbox) + bitmap->bbox = entry->bbox; + else + { + font_funcs->get_glyph_bbox(fontface->get_font_object(fontface), bitmap); + entry->bbox = bitmap->bbox; + entry->has_bbox = 1; + } + } + LeaveCriticalSection(&fontface->cs); +} + static int fontface_cache_compare(const void *k, const struct wine_rb_entry *e) { const struct cache_entry *entry = WINE_RB_ENTRY_VALUE(e, const struct cache_entry, entry); @@ -5819,8 +5845,6 @@ static UINT32 get_glyph_bitmap_pitch(DWRITE_RENDERING_MODE1 rendering_mode, INT static void glyphrunanalysis_get_texturebounds(struct dwrite_glyphrunanalysis *analysis, RECT *bounds) { struct dwrite_glyphbitmap glyph_bitmap; - IDWriteFontFace4 *fontface; - HRESULT hr; UINT32 i;
if (analysis->flags & RUNANALYSIS_BOUNDS_READY) { @@ -5831,12 +5855,8 @@ static void glyphrunanalysis_get_texturebounds(struct dwrite_glyphrunanalysis *a if (analysis->run.isSideways) FIXME("sideways runs are not supported.\n");
- hr = IDWriteFontFace_QueryInterface(analysis->run.fontFace, &IID_IDWriteFontFace4, (void **)&fontface); - if (FAILED(hr)) - WARN("failed to get IDWriteFontFace4, 0x%08x\n", hr); - memset(&glyph_bitmap, 0, sizeof(glyph_bitmap)); - glyph_bitmap.simulations = IDWriteFontFace4_GetSimulations(fontface); + glyph_bitmap.simulations = IDWriteFontFace_GetSimulations(analysis->run.fontFace); glyph_bitmap.emsize = analysis->run.fontEmSize; glyph_bitmap.nohint = is_natural_rendering_mode(analysis->rendering_mode); if (analysis->flags & RUNANALYSIS_USE_TRANSFORM) @@ -5847,7 +5867,7 @@ static void glyphrunanalysis_get_texturebounds(struct dwrite_glyphrunanalysis *a UINT32 bitmap_size;
glyph_bitmap.glyph = analysis->run.glyphIndices[i]; - font_funcs->get_glyph_bbox(fontface, &glyph_bitmap); + dwrite_fontface_get_glyph_bbox(analysis->run.fontFace, &glyph_bitmap);
bitmap_size = get_glyph_bitmap_pitch(analysis->rendering_mode, bbox->right - bbox->left) * (bbox->bottom - bbox->top); @@ -5858,8 +5878,6 @@ static void glyphrunanalysis_get_texturebounds(struct dwrite_glyphrunanalysis *a UnionRect(&analysis->bounds, &analysis->bounds, bbox); }
- IDWriteFontFace4_Release(fontface); - analysis->flags |= RUNANALYSIS_BOUNDS_READY; *bounds = analysis->bounds; } @@ -5946,7 +5964,7 @@ static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis) BOOL is_1bpp;
glyph_bitmap.glyph = analysis->run.glyphIndices[i]; - font_funcs->get_glyph_bbox(fontface, &glyph_bitmap); + dwrite_fontface_get_glyph_bbox(analysis->run.fontFace, &glyph_bitmap);
if (IsRectEmpty(bbox)) continue; diff --git a/dlls/dwrite/freetype.c b/dlls/dwrite/freetype.c index dede7c46c9c..34b08cfd2a4 100644 --- a/dlls/dwrite/freetype.c +++ b/dlls/dwrite/freetype.c @@ -76,6 +76,7 @@ MAKE_FUNCPTR(FT_Done_FreeType); MAKE_FUNCPTR(FT_Done_Glyph); MAKE_FUNCPTR(FT_Done_Size); MAKE_FUNCPTR(FT_Get_First_Char); +MAKE_FUNCPTR(FT_Get_Glyph); MAKE_FUNCPTR(FT_Get_Kerning); MAKE_FUNCPTR(FT_Get_Sfnt_Table); MAKE_FUNCPTR(FT_Glyph_Copy); @@ -184,6 +185,7 @@ static BOOL init_freetype(void) LOAD_FUNCPTR(FT_Done_Glyph) LOAD_FUNCPTR(FT_Done_Size) LOAD_FUNCPTR(FT_Get_First_Char) + LOAD_FUNCPTR(FT_Get_Glyph) LOAD_FUNCPTR(FT_Get_Kerning) LOAD_FUNCPTR(FT_Get_Sfnt_Table) LOAD_FUNCPTR(FT_Glyph_Copy) @@ -572,7 +574,7 @@ static BOOL is_face_scalable(void *key) return FALSE; }
-static BOOL get_glyph_transform(void *key, struct dwrite_glyphbitmap *bitmap, FT_Matrix *ret) +static BOOL get_glyph_transform(struct dwrite_glyphbitmap *bitmap, FT_Matrix *ret) { FT_Matrix m;
@@ -583,7 +585,7 @@ static BOOL get_glyph_transform(void *key, struct dwrite_glyphbitmap *bitmap, FT
/* Some fonts provide mostly bitmaps and very few outlines, for example for .notdef. Disable transform if that's the case. */ - if (!is_face_scalable(key) || (!bitmap->m && !bitmap->simulations)) + if (!bitmap->m && !bitmap->simulations) return FALSE;
if (bitmap->simulations & DWRITE_FONT_SIMULATIONS_OBLIQUE) { @@ -602,42 +604,42 @@ static BOOL get_glyph_transform(void *key, struct dwrite_glyphbitmap *bitmap, FT return TRUE; }
-static void CDECL freetype_get_glyph_bbox(void *key, struct dwrite_glyphbitmap *bitmap) +static void CDECL freetype_get_glyph_bbox(font_object_handle object, struct dwrite_glyphbitmap *bitmap) { - FTC_ImageTypeRec imagetype; + FT_Face face = object; + FT_Glyph glyph = NULL; FT_BBox bbox = { 0 }; BOOL needs_transform; - FT_Glyph glyph; FT_Matrix m; + FT_Size size;
- RtlEnterCriticalSection(&freetype_cs); + SetRectEmpty(&bitmap->bbox);
- needs_transform = get_glyph_transform(key, bitmap, &m); + if (!(size = freetype_set_face_size(face, bitmap->emsize))) + return;
- imagetype.face_id = key; - imagetype.width = 0; - imagetype.height = bitmap->emsize; - imagetype.flags = needs_transform ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT; + needs_transform = FT_IS_SCALABLE(face) && get_glyph_transform(bitmap, &m);
- if (pFTC_ImageCache_Lookup(image_cache, &imagetype, bitmap->glyph, &glyph, NULL) == 0) { - if (needs_transform) { - FT_Glyph glyph_copy; + if (pFT_Load_Glyph(face, bitmap->glyph, needs_transform ? FT_LOAD_NO_BITMAP : 0)) + { + WARN("Failed to load glyph %u.\n", bitmap->glyph); + pFT_Done_Size(size); + return; + }
- if (pFT_Glyph_Copy(glyph, &glyph_copy) == 0) { - if (bitmap->simulations & DWRITE_FONT_SIMULATIONS_BOLD) - embolden_glyph(glyph_copy, bitmap->emsize); + pFT_Get_Glyph(face->glyph, &glyph); + if (needs_transform) + { + if (bitmap->simulations & DWRITE_FONT_SIMULATIONS_BOLD) + embolden_glyph(glyph, bitmap->emsize);
- /* Includes oblique and user transform. */ - pFT_Glyph_Transform(glyph_copy, &m, NULL); - pFT_Glyph_Get_CBox(glyph_copy, FT_GLYPH_BBOX_PIXELS, &bbox); - pFT_Done_Glyph(glyph_copy); - } - } - else - pFT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &bbox); + /* Includes oblique and user transform. */ + pFT_Glyph_Transform(glyph, &m, NULL); }
- RtlLeaveCriticalSection(&freetype_cs); + pFT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_PIXELS, &bbox); + pFT_Done_Glyph(glyph); + pFT_Done_Size(size);
/* flip Y axis */ SetRect(&bitmap->bbox, bbox.xMin, -bbox.yMax, bbox.xMax, -bbox.yMin); @@ -744,7 +746,7 @@ static BOOL CDECL freetype_get_glyph_bitmap(void *key, struct dwrite_glyphbitmap
RtlEnterCriticalSection(&freetype_cs);
- needs_transform = get_glyph_transform(key, bitmap, &m); + needs_transform = is_face_scalable(key) && get_glyph_transform(bitmap, &m);
imagetype.face_id = key; imagetype.width = 0; @@ -865,7 +867,7 @@ static INT32 CDECL null_get_glyph_advance(font_object_handle object, float emsiz return 0; }
-static void CDECL null_get_glyph_bbox(void *key, struct dwrite_glyphbitmap *bitmap) +static void CDECL null_get_glyph_bbox(font_object_handle object, struct dwrite_glyphbitmap *bitmap) { SetRectEmpty(&bitmap->bbox); }
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/dwrite_private.h | 2 +- dlls/dwrite/font.c | 103 ++++++++++++++++++++++++----------- dlls/dwrite/freetype.c | 53 ++++++------------ 3 files changed, 90 insertions(+), 68 deletions(-)
diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index b166766a167..1ac50747ec6 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -735,7 +735,7 @@ struct font_backend_funcs INT32 (CDECL *get_glyph_advance)(font_object_handle object, float em_size, UINT16 glyph, DWRITE_MEASURING_MODE measuring_mode, BOOL *has_contours); void (CDECL *get_glyph_bbox)(font_object_handle object, struct dwrite_glyphbitmap *bitmap_desc); - BOOL (CDECL *get_glyph_bitmap)(void *key, struct dwrite_glyphbitmap *bitmap_desc); + BOOL (CDECL *get_glyph_bitmap)(font_object_handle object, struct dwrite_glyphbitmap *bitmap_desc); void (CDECL *get_design_glyph_metrics)(font_object_handle object, UINT16 upem, UINT16 ascent, unsigned int simulations, UINT16 glyph, DWRITE_GLYPH_METRICS *metrics); }; diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index c6ef61f7fe3..05aea75d52d 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -61,21 +61,26 @@ struct cache_entry struct cache_key key; float advance; RECT bbox; + BYTE *bitmap; + unsigned int bitmap_size; + unsigned int is_1bpp : 1; unsigned int has_contours : 1; unsigned int has_advance : 1; unsigned int has_bbox : 1; + unsigned int has_bitmap : 1; };
-static size_t fontface_get_cache_entry_size(const struct cache_entry *entry) +static void fontface_release_cache_entry(struct cache_entry *entry) { - return sizeof(*entry); + free(entry->bitmap); + free(entry); }
-static struct cache_entry * fontface_get_cache_entry(struct dwrite_fontface *fontface, const struct cache_key *key) +static struct cache_entry * fontface_get_cache_entry(struct dwrite_fontface *fontface, size_t size, + const struct cache_key *key) { struct cache_entry *entry, *old_entry; struct wine_rb_entry *e; - size_t size;
if (!(e = wine_rb_get(&fontface->cache.tree, key))) { @@ -83,14 +88,15 @@ static struct cache_entry * fontface_get_cache_entry(struct dwrite_fontface *fon entry->key = *key; list_init(&entry->mru);
- size = fontface_get_cache_entry_size(entry); + size += sizeof(*entry); + if ((fontface->cache.size + size > fontface->cache.max_size) && !list_empty(&fontface->cache.mru)) { old_entry = LIST_ENTRY(list_tail(&fontface->cache.mru), struct cache_entry, mru); - fontface->cache.size -= fontface_get_cache_entry_size(old_entry); + fontface->cache.size -= (old_entry->bitmap_size + sizeof(*old_entry)); wine_rb_remove(&fontface->cache.tree, &old_entry->entry); list_remove(&old_entry->mru); - free(old_entry); + fontface_release_cache_entry(old_entry); }
if (wine_rb_put(&fontface->cache.tree, &key, &entry->entry) == -1) @@ -118,7 +124,7 @@ static float fontface_get_glyph_advance(struct dwrite_fontface *fontface, float struct cache_entry *entry; BOOL value;
- if (!(entry = fontface_get_cache_entry(fontface, &key))) + if (!(entry = fontface_get_cache_entry(fontface, 0, &key))) return 0.0f;
if (!entry->has_advance) @@ -144,7 +150,7 @@ void dwrite_fontface_get_glyph_bbox(IDWriteFontFace *iface, struct dwrite_glyphb { font_funcs->get_glyph_bbox(fontface->get_font_object(fontface), bitmap); } - else if ((entry = fontface_get_cache_entry(fontface, &key))) + else if ((entry = fontface_get_cache_entry(fontface, 0, &key))) { if (entry->has_bbox) bitmap->bbox = entry->bbox; @@ -158,6 +164,52 @@ void dwrite_fontface_get_glyph_bbox(IDWriteFontFace *iface, struct dwrite_glyphb LeaveCriticalSection(&fontface->cs); }
+static unsigned int get_glyph_bitmap_pitch(DWRITE_RENDERING_MODE1 rendering_mode, INT width) +{ + return rendering_mode == DWRITE_RENDERING_MODE1_ALIASED ? ((width + 31) >> 5) << 2 : (width + 3) / 4 * 4; +} + +static HRESULT dwrite_fontface_get_glyph_bitmap(struct dwrite_fontface *fontface, DWRITE_RENDERING_MODE rendering_mode, + BOOL *is_1bpp, struct dwrite_glyphbitmap *bitmap) +{ + struct cache_key key = { .size = bitmap->emsize, .glyph = bitmap->glyph, .mode = DWRITE_MEASURING_MODE_NATURAL }; + const RECT *bbox = &bitmap->bbox; + struct cache_entry *entry; + unsigned int bitmap_size; + HRESULT hr = S_OK; + + bitmap_size = get_glyph_bitmap_pitch(rendering_mode, bbox->right - bbox->left) * + (bbox->bottom - bbox->top); + + EnterCriticalSection(&fontface->cs); + /* For now bypass cache for transformed cases. */ + if (bitmap->m && memcmp(bitmap->m, &identity, sizeof(*bitmap->m))) + { + *is_1bpp = font_funcs->get_glyph_bitmap(fontface->get_font_object(fontface), bitmap); + } + else if ((entry = fontface_get_cache_entry(fontface, bitmap_size, &key))) + { + if (entry->has_bitmap) + { + memcpy(bitmap->buf, entry->bitmap, entry->bitmap_size); + } + else + { + entry->is_1bpp = font_funcs->get_glyph_bitmap(fontface->get_font_object(fontface), bitmap); + entry->bitmap_size = bitmap_size; + if ((entry->bitmap = malloc(entry->bitmap_size))) + memcpy(entry->bitmap, bitmap->buf, entry->bitmap_size); + entry->has_bitmap = 1; + } + *is_1bpp = entry->is_1bpp; + } + else + hr = E_FAIL; + LeaveCriticalSection(&fontface->cs); + + return hr; +} + static int fontface_cache_compare(const void *k, const struct wine_rb_entry *e) { const struct cache_entry *entry = WINE_RB_ENTRY_VALUE(e, const struct cache_entry, entry); @@ -183,7 +235,7 @@ static void fontface_cache_clear(struct dwrite_fontface *fontface) LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &fontface->cache.mru, struct cache_entry, mru) { list_remove(&entry->mru); - free(entry); + fontface_release_cache_entry(entry); } memset(&fontface->cache, 0, sizeof(fontface->cache)); } @@ -5837,11 +5889,6 @@ static BOOL is_natural_rendering_mode(DWRITE_RENDERING_MODE1 mode) } }
-static UINT32 get_glyph_bitmap_pitch(DWRITE_RENDERING_MODE1 rendering_mode, INT width) -{ - return rendering_mode == DWRITE_RENDERING_MODE1_ALIASED ? ((width + 31) >> 5) << 2 : (width + 3) / 4 * 4; -} - static void glyphrunanalysis_get_texturebounds(struct dwrite_glyphrunanalysis *analysis, RECT *bounds) { struct dwrite_glyphbitmap glyph_bitmap; @@ -5917,19 +5964,12 @@ static inline BYTE *get_pixel_ptr(BYTE *ptr, DWRITE_TEXTURE_TYPE type, const REC static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis) { static const BYTE masks[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01}; + struct dwrite_fontface *fontface = unsafe_impl_from_IDWriteFontFace(analysis->run.fontFace); struct dwrite_glyphbitmap glyph_bitmap; - IDWriteFontFace4 *fontface; D2D_POINT_2F origin; UINT32 i, size; - HRESULT hr; RECT *bbox;
- hr = IDWriteFontFace_QueryInterface(analysis->run.fontFace, &IID_IDWriteFontFace4, (void **)&fontface); - if (FAILED(hr)) { - WARN("failed to get IDWriteFontFace4, 0x%08x\n", hr); - return hr; - } - size = (analysis->bounds.right - analysis->bounds.left)*(analysis->bounds.bottom - analysis->bounds.top); if (analysis->texture_type == DWRITE_TEXTURE_CLEARTYPE_3x1) size *= 3; @@ -5937,28 +5977,25 @@ static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis) { WARN("Failed to allocate run bitmap, %s, type %s.\n", wine_dbgstr_rect(&analysis->bounds), analysis->texture_type == DWRITE_TEXTURE_CLEARTYPE_3x1 ? "3x1" : "1x1"); - IDWriteFontFace4_Release(fontface); return E_OUTOFMEMORY; }
origin.x = origin.y = 0.0f;
memset(&glyph_bitmap, 0, sizeof(glyph_bitmap)); - glyph_bitmap.simulations = IDWriteFontFace4_GetSimulations(fontface); + glyph_bitmap.simulations = fontface->simulations; glyph_bitmap.emsize = analysis->run.fontEmSize; glyph_bitmap.nohint = is_natural_rendering_mode(analysis->rendering_mode); glyph_bitmap.aliased = analysis->rendering_mode == DWRITE_RENDERING_MODE1_ALIASED; if (analysis->flags & RUNANALYSIS_USE_TRANSFORM) glyph_bitmap.m = &analysis->m; if (!(glyph_bitmap.buf = malloc(analysis->max_glyph_bitmap_size))) - { - IDWriteFontFace4_Release(fontface); return E_OUTOFMEMORY; - }
bbox = &glyph_bitmap.bbox;
- for (i = 0; i < analysis->run.glyphCount; i++) { + for (i = 0; i < analysis->run.glyphCount; ++i) + { BYTE *src = glyph_bitmap.buf, *dst; int x, y, width, height; BOOL is_1bpp; @@ -5974,7 +6011,11 @@ static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis)
glyph_bitmap.pitch = get_glyph_bitmap_pitch(analysis->rendering_mode, width); memset(src, 0, height * glyph_bitmap.pitch); - is_1bpp = font_funcs->get_glyph_bitmap(fontface, &glyph_bitmap); + if (FAILED(dwrite_fontface_get_glyph_bitmap(fontface, analysis->rendering_mode, &is_1bpp, &glyph_bitmap))) + { + WARN("Failed to render glyph[%u] = %#x.\n", i, glyph_bitmap.glyph); + continue; + }
OffsetRect(bbox, analysis->origins[i].x, analysis->origins[i].y);
@@ -6023,8 +6064,6 @@ static HRESULT glyphrunanalysis_render(struct dwrite_glyphrunanalysis *analysis) } free(glyph_bitmap.buf);
- IDWriteFontFace4_Release(fontface); - analysis->flags |= RUNANALYSIS_BITMAP_READY;
/* we don't need this anymore */ diff --git a/dlls/dwrite/freetype.c b/dlls/dwrite/freetype.c index 34b08cfd2a4..3b9676a1af1 100644 --- a/dlls/dwrite/freetype.c +++ b/dlls/dwrite/freetype.c @@ -564,16 +564,6 @@ static inline void ft_matrix_from_dwrite_matrix(const DWRITE_MATRIX *m, FT_Matri ft_matrix->yy = m->m22 * 0x10000; }
-/* Should be used only while holding 'freetype_cs' */ -static BOOL is_face_scalable(void *key) -{ - FT_Face face; - if (pFTC_Manager_LookupFace(cache_manager, key, &face) == 0) - return FT_IS_SCALABLE(face); - else - return FALSE; -} - static BOOL get_glyph_transform(struct dwrite_glyphbitmap *bitmap, FT_Matrix *ret) { FT_Matrix m; @@ -736,49 +726,42 @@ static BOOL freetype_get_aa_glyph_bitmap(struct dwrite_glyphbitmap *bitmap, FT_G return ret; }
-static BOOL CDECL freetype_get_glyph_bitmap(void *key, struct dwrite_glyphbitmap *bitmap) +static BOOL CDECL freetype_get_glyph_bitmap(font_object_handle object, struct dwrite_glyphbitmap *bitmap) { - FTC_ImageTypeRec imagetype; + FT_Face face = object; BOOL needs_transform; BOOL ret = FALSE; FT_Glyph glyph; + FT_Size size; FT_Matrix m;
- RtlEnterCriticalSection(&freetype_cs); - - needs_transform = is_face_scalable(key) && get_glyph_transform(bitmap, &m); + if (!(size = freetype_set_face_size(face, bitmap->emsize))) + return FALSE;
- imagetype.face_id = key; - imagetype.width = 0; - imagetype.height = bitmap->emsize; - imagetype.flags = needs_transform ? FT_LOAD_NO_BITMAP : FT_LOAD_DEFAULT; + needs_transform = FT_IS_SCALABLE(face) && get_glyph_transform(bitmap, &m);
- if (pFTC_ImageCache_Lookup(image_cache, &imagetype, bitmap->glyph, &glyph, NULL) == 0) { - FT_Glyph glyph_copy; + if (!pFT_Load_Glyph(face, bitmap->glyph, needs_transform ? FT_LOAD_NO_BITMAP : 0)) + { + pFT_Get_Glyph(face->glyph, &glyph);
- if (needs_transform) { - if (pFT_Glyph_Copy(glyph, &glyph_copy) == 0) { - if (bitmap->simulations & DWRITE_FONT_SIMULATIONS_BOLD) - embolden_glyph(glyph_copy, bitmap->emsize); + if (needs_transform) + { + if (bitmap->simulations & DWRITE_FONT_SIMULATIONS_BOLD) + embolden_glyph(glyph, bitmap->emsize);
- /* Includes oblique and user transform. */ - pFT_Glyph_Transform(glyph_copy, &m, NULL); - glyph = glyph_copy; - } + /* Includes oblique and user transform. */ + pFT_Glyph_Transform(glyph, &m, NULL); } - else - glyph_copy = NULL;
if (bitmap->aliased) ret = freetype_get_aliased_glyph_bitmap(bitmap, glyph); else ret = freetype_get_aa_glyph_bitmap(bitmap, glyph);
- if (glyph_copy) - pFT_Done_Glyph(glyph_copy); + pFT_Done_Glyph(glyph); }
- RtlLeaveCriticalSection(&freetype_cs); + pFT_Done_Size(size);
return ret; } @@ -872,7 +855,7 @@ static void CDECL null_get_glyph_bbox(font_object_handle object, struct dwrite_g SetRectEmpty(&bitmap->bbox); }
-static BOOL CDECL null_get_glyph_bitmap(void *key, struct dwrite_glyphbitmap *bitmap) +static BOOL CDECL null_get_glyph_bitmap(font_object_handle object, struct dwrite_glyphbitmap *bitmap) { return FALSE; }
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/dwrite/dwrite_private.h | 8 ---- dlls/dwrite/font.c | 74 +--------------------------- dlls/dwrite/freetype.c | 93 +----------------------------------- 3 files changed, 3 insertions(+), 172 deletions(-)
diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h index 1ac50747ec6..f83372acc9e 100644 --- a/dlls/dwrite/dwrite_private.h +++ b/dlls/dwrite/dwrite_private.h @@ -717,18 +717,10 @@ extern HRESULT shape_check_typographic_feature(struct scriptshaping_context *con struct font_data_context; extern HMODULE dwrite_module DECLSPEC_HIDDEN;
-struct font_callback_funcs -{ - int (CDECL *get_font_data)(void *key, const void **data_ptr, UINT64 *data_size, unsigned int *index, - struct font_data_context **context); - void (CDECL *release_font_data)(struct font_data_context *context); -}; - struct font_backend_funcs { font_object_handle (CDECL *create_font_object)(const void *data_ptr, UINT64 data_size, unsigned int index); void (CDECL *release_font_object)(font_object_handle object); - void (CDECL *notify_release)(void *key); int (CDECL *get_glyph_outline)(font_object_handle object, float emsize, unsigned int simulations, UINT16 glyph, struct dwrite_outline *outline); UINT16 (CDECL *get_glyph_count)(font_object_handle object); diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c index 05aea75d52d..cb4f856524c 100644 --- a/dlls/dwrite/font.c +++ b/dlls/dwrite/font.c @@ -837,7 +837,6 @@ static ULONG WINAPI dwritefontface_Release(IDWriteFontFace5 *iface) for (i = 0; i < ARRAY_SIZE(fontface->glyphs); i++) free(fontface->glyphs[i]);
- font_funcs->notify_release(iface); font_funcs->release_font_object(fontface->font_object); if (fontface->stream) { @@ -8142,81 +8141,12 @@ HRESULT create_fontset_builder(IDWriteFactory7 *factory, IDWriteFontSetBuilder2 return S_OK; }
-struct font_data_context -{ - IDWriteFontFileStream *stream; - void *context; -}; - -static int CDECL get_font_data_cb(void *key, const void **data_ptr, UINT64 *data_size, - unsigned int *index, struct font_data_context **ret_context) -{ - IDWriteFontFace *fontface = key; - struct font_data_context *context; - IDWriteFontFileStream *stream; - IDWriteFontFile *file; - unsigned int count; - void *data_context; - HRESULT hr; - - *ret_context = NULL; - - count = 1; - if (FAILED(IDWriteFontFace_GetFiles(fontface, &count, &file))) return 1; - - hr = get_filestream_from_file(file, &stream); - IDWriteFontFile_Release(file); - if (FAILED(hr)) return 1; - - hr = IDWriteFontFileStream_GetFileSize(stream, data_size); - if (FAILED(hr)) - { - IDWriteFontFileStream_Release(stream); - return 1; - } - - hr = IDWriteFontFileStream_ReadFileFragment(stream, data_ptr, 0, *data_size, &data_context); - if (FAILED(hr)) - { - IDWriteFontFileStream_Release(stream); - return 1; - } - - if (!(context = malloc(sizeof(*context)))) - { - IDWriteFontFileStream_Release(stream); - return 1; - } - - context->stream = stream; - context->context = data_context; - - *ret_context = context; - *index = IDWriteFontFace_GetIndex(fontface); - - return 0; -} - -static void CDECL release_font_data_cb(struct font_data_context *context) -{ - if (!context) return; - IDWriteFontFileStream_ReleaseFileFragment(context->stream, context->context); - IDWriteFontFileStream_Release(context->stream); - free(context); -} - -struct font_callback_funcs callback_funcs = -{ - get_font_data_cb, - release_font_data_cb, -}; - void init_font_backend(void) { - __wine_init_unix_lib(dwrite_module, DLL_PROCESS_ATTACH, &callback_funcs, &font_funcs); + __wine_init_unix_lib(dwrite_module, DLL_PROCESS_ATTACH, NULL, &font_funcs); }
void release_font_backend(void) { - __wine_init_unix_lib(dwrite_module, DLL_PROCESS_DETACH, &callback_funcs, NULL); + __wine_init_unix_lib(dwrite_module, DLL_PROCESS_DETACH, NULL, NULL); } diff --git a/dlls/dwrite/freetype.c b/dlls/dwrite/freetype.c index 3b9676a1af1..daaff6a3f8c 100644 --- a/dlls/dwrite/freetype.c +++ b/dlls/dwrite/freetype.c @@ -29,7 +29,7 @@
#ifdef HAVE_FT2BUILD_H #include <ft2build.h> -#include FT_CACHE_H +#include FT_GLYPH_H #include FT_FREETYPE_H #include FT_OUTLINE_H #include FT_TRUETYPE_TABLES_H @@ -47,19 +47,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
-static RTL_CRITICAL_SECTION freetype_cs; -static RTL_CRITICAL_SECTION_DEBUG critsect_debug = -{ - 0, 0, &freetype_cs, - { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": freetype_cs") } -}; -static RTL_CRITICAL_SECTION freetype_cs = { &critsect_debug, -1, 0, 0, 0, 0 }; - static void *ft_handle = NULL; static FT_Library library = 0; -static FTC_Manager cache_manager = 0; -static FTC_ImageCache image_cache = 0; typedef struct { FT_Int major; @@ -67,8 +56,6 @@ typedef struct FT_Int patch; } FT_Version_t;
-static const struct font_callback_funcs *callback_funcs; - #define MAKE_FUNCPTR(f) static typeof(f) * p##f = NULL MAKE_FUNCPTR(FT_Activate_Size); MAKE_FUNCPTR(FT_Done_Face); @@ -98,53 +85,9 @@ MAKE_FUNCPTR(FT_Outline_New); MAKE_FUNCPTR(FT_Outline_Transform); MAKE_FUNCPTR(FT_Outline_Translate); MAKE_FUNCPTR(FT_Set_Pixel_Sizes); -MAKE_FUNCPTR(FTC_ImageCache_Lookup); -MAKE_FUNCPTR(FTC_ImageCache_New); -MAKE_FUNCPTR(FTC_Manager_New); -MAKE_FUNCPTR(FTC_Manager_Done); -MAKE_FUNCPTR(FTC_Manager_LookupFace); -MAKE_FUNCPTR(FTC_Manager_LookupSize); -MAKE_FUNCPTR(FTC_Manager_RemoveFaceID); #undef MAKE_FUNCPTR static FT_Error (*pFT_Outline_EmboldenXY)(FT_Outline *, FT_Pos, FT_Pos);
-static void face_finalizer(void *object) -{ - FT_Face face = object; - callback_funcs->release_font_data((struct font_data_context *)face->generic.data); -} - -static FT_Error face_requester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *face) -{ - struct font_data_context *context; - const void *data_ptr; - FT_Error fterror; - UINT64 data_size; - UINT32 index; - - *face = NULL; - - if (!face_id) - { - WARN("NULL fontface requested.\n"); - return FT_Err_Ok; - } - - if (callback_funcs->get_font_data(face_id, &data_ptr, &data_size, &index, &context)) - return FT_Err_Ok; - - fterror = pFT_New_Memory_Face(library, data_ptr, data_size, index, face); - if (fterror == FT_Err_Ok) - { - (*face)->generic.data = context; - (*face)->generic.finalizer = face_finalizer; - } - else - callback_funcs->release_font_data(context); - - return fterror; -} - static FT_Size freetype_set_face_size(FT_Face face, FT_UInt emsize) { FT_Size size; @@ -207,13 +150,6 @@ static BOOL init_freetype(void) LOAD_FUNCPTR(FT_Outline_Transform) LOAD_FUNCPTR(FT_Outline_Translate) LOAD_FUNCPTR(FT_Set_Pixel_Sizes) - LOAD_FUNCPTR(FTC_ImageCache_Lookup) - LOAD_FUNCPTR(FTC_ImageCache_New) - LOAD_FUNCPTR(FTC_Manager_New) - LOAD_FUNCPTR(FTC_Manager_Done) - LOAD_FUNCPTR(FTC_Manager_LookupFace) - LOAD_FUNCPTR(FTC_Manager_LookupSize) - LOAD_FUNCPTR(FTC_Manager_RemoveFaceID) #undef LOAD_FUNCPTR pFT_Outline_EmboldenXY = dlsym(ft_handle, "FT_Outline_EmboldenXY");
@@ -225,18 +161,6 @@ static BOOL init_freetype(void) } pFT_Library_Version(library, &FT_Version.major, &FT_Version.minor, &FT_Version.patch);
- /* init cache manager */ - if (pFTC_Manager_New(library, 0, 0, 0, &face_requester, NULL, &cache_manager) != 0 || - pFTC_ImageCache_New(cache_manager, &image_cache) != 0) { - - ERR("Failed to init FreeType cache\n"); - pFTC_Manager_Done(cache_manager); - pFT_Done_FreeType(library); - dlclose(ft_handle); - ft_handle = NULL; - return FALSE; - } - TRACE("FreeType version is %d.%d.%d\n", FT_Version.major, FT_Version.minor, FT_Version.patch); return TRUE;
@@ -264,13 +188,6 @@ static void CDECL freetype_release_font_object(font_object_handle object) pFT_Done_Face(object); }
-static void CDECL freetype_notify_release(void *key) -{ - RtlEnterCriticalSection(&freetype_cs); - pFTC_Manager_RemoveFaceID(cache_manager, key); - RtlLeaveCriticalSection(&freetype_cs); -} - static void CDECL freetype_get_design_glyph_metrics(font_object_handle object, UINT16 upem, UINT16 ascent, unsigned int simulations, UINT16 glyph, DWRITE_GLYPH_METRICS *ret) { @@ -793,7 +710,6 @@ const static struct font_backend_funcs freetype_funcs = { freetype_create_font_object, freetype_release_font_object, - freetype_notify_release, freetype_get_glyph_outline, freetype_get_glyph_count, freetype_get_glyph_advance, @@ -804,7 +720,6 @@ const static struct font_backend_funcs freetype_funcs =
static NTSTATUS init_freetype_lib(HMODULE module, DWORD reason, const void *ptr_in, void *ptr_out) { - callback_funcs = ptr_in; if (!init_freetype()) return STATUS_DLL_NOT_FOUND; *(const struct font_backend_funcs **)ptr_out = &freetype_funcs; return STATUS_SUCCESS; @@ -812,7 +727,6 @@ static NTSTATUS init_freetype_lib(HMODULE module, DWORD reason, const void *ptr_
static NTSTATUS release_freetype_lib(void) { - pFTC_Manager_Done(cache_manager); pFT_Done_FreeType(library); return STATUS_SUCCESS; } @@ -828,10 +742,6 @@ static void CDECL null_release_font_object(font_object_handle object) { }
-static void CDECL null_notify_release(void *key) -{ -} - static int CDECL null_get_glyph_outline(font_object_handle object, float emSize, unsigned int simulations, UINT16 glyph, struct dwrite_outline *outline) { @@ -869,7 +779,6 @@ const static struct font_backend_funcs null_funcs = { null_create_font_object, null_release_font_object, - null_notify_release, null_get_glyph_outline, null_get_glyph_count, null_get_glyph_advance,