[PATCH 5/5] dwrite: Get rid of cmap cache.
Nikolay Sivov
nsivov at codeweavers.com
Tue Jun 9 04:14:37 CDT 2020
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
dlls/dwrite/dwrite_private.h | 8 ++---
dlls/dwrite/font.c | 37 ++++++++++------------
dlls/dwrite/freetype.c | 60 ------------------------------------
dlls/dwrite/opentype.c | 4 ++-
4 files changed, 22 insertions(+), 87 deletions(-)
diff --git a/dlls/dwrite/dwrite_private.h b/dlls/dwrite/dwrite_private.h
index 5e6946717b3..2a8a4d47414 100644
--- a/dlls/dwrite/dwrite_private.h
+++ b/dlls/dwrite/dwrite_private.h
@@ -259,9 +259,10 @@ struct dwrite_fontface
unsigned int ascent;
unsigned int descent;
} typo_metrics;
- INT charmap;
UINT32 flags;
+ struct dwrite_cmap cmap;
+
struct dwrite_fonttable vdmx;
struct dwrite_fonttable gasp;
struct dwrite_fonttable cpal;
@@ -340,8 +341,6 @@ extern void factory_unlock(IDWriteFactory7 *factory) DECLSPEC_HIDDEN;
extern HRESULT create_inmemory_fileloader(IDWriteFontFileLoader**) DECLSPEC_HIDDEN;
extern HRESULT create_font_resource(IDWriteFactory7 *factory, IDWriteFontFile *file, UINT32 face_index,
IDWriteFontResource **resource) DECLSPEC_HIDDEN;
-extern HRESULT fontface_get_glyphs(struct dwrite_fontface *fontface, UINT32 const *codepoints,
- UINT32 count, UINT16 *glyphs);
struct dwrite_fontface;
@@ -462,13 +461,10 @@ extern HRESULT freetype_get_glyphrun_outline(IDWriteFontFace5 *fontface, float e
float const *advances, DWRITE_GLYPH_OFFSET const *offsets, unsigned int count, BOOL is_rtl,
IDWriteGeometrySink *sink) DECLSPEC_HIDDEN;
extern UINT16 freetype_get_glyphcount(IDWriteFontFace5 *fontface) DECLSPEC_HIDDEN;
-extern void freetype_get_glyphs(IDWriteFontFace5 *fontface, INT charmap, UINT32 const *codepoints, UINT32 count,
- UINT16 *glyphs) DECLSPEC_HIDDEN;
extern BOOL freetype_has_kerning_pairs(IDWriteFontFace5 *fontface) DECLSPEC_HIDDEN;
extern INT32 freetype_get_kerning_pair_adjustment(IDWriteFontFace5 *fontface, UINT16 left, UINT16 right) DECLSPEC_HIDDEN;
extern void freetype_get_glyph_bbox(struct dwrite_glyphbitmap *bitmap_desc) DECLSPEC_HIDDEN;
extern BOOL freetype_get_glyph_bitmap(struct dwrite_glyphbitmap*) DECLSPEC_HIDDEN;
-extern INT freetype_get_charmap_index(IDWriteFontFace5 *fontface) DECLSPEC_HIDDEN;
extern INT32 freetype_get_glyph_advance(IDWriteFontFace5 *fontface, FLOAT emsize, UINT16 index,
DWRITE_MEASURING_MODE measuring_mode, BOOL *has_contours) DECLSPEC_HIDDEN;
extern void freetype_get_design_glyph_bbox(IDWriteFontFace4*,UINT16,UINT16,RECT*) DECLSPEC_HIDDEN;
diff --git a/dlls/dwrite/font.c b/dlls/dwrite/font.c
index f180ba765b8..7f5cce4e4b2 100644
--- a/dlls/dwrite/font.c
+++ b/dlls/dwrite/font.c
@@ -273,20 +273,22 @@ static UINT16 dwrite_get_font_upem(void *context)
return fontface->metrics.designUnitsPerEm;
}
+static UINT16 dwritefontface_get_glyph(struct dwrite_fontface *fontface, unsigned int ch)
+{
+ dwrite_cmap_init(&fontface->cmap, NULL, fontface->index, fontface->type);
+ return opentype_cmap_get_glyph(&fontface->cmap, ch);
+}
+
static BOOL dwrite_has_glyph(void *context, unsigned int codepoint)
{
struct dwrite_fontface *fontface = context;
- UINT16 index = 0;
- fontface_get_glyphs(fontface, &codepoint, 1, &index);
- return !!index;
+ return !!dwritefontface_get_glyph(fontface, codepoint);
}
static UINT16 dwrite_get_glyph(void *context, unsigned int codepoint)
{
struct dwrite_fontface *fontface = context;
- UINT16 index = 0;
- fontface_get_glyphs(fontface, &codepoint, 1, &index);
- return index;
+ return dwritefontface_get_glyph(fontface, codepoint);
}
static const struct shaping_font_ops dwrite_font_ops =
@@ -616,6 +618,7 @@ static ULONG WINAPI dwritefontface_Release(IDWriteFontFace5 *iface)
freetype_notify_cacheremove(iface);
+ dwrite_cmap_release(&fontface->cmap);
IDWriteFactory7_Release(fontface->factory);
heap_free(fontface);
}
@@ -732,17 +735,11 @@ static HRESULT WINAPI dwritefontface_GetDesignGlyphMetrics(IDWriteFontFace5 *ifa
return S_OK;
}
-HRESULT fontface_get_glyphs(struct dwrite_fontface *fontface, UINT32 const *codepoints,
- UINT32 count, UINT16 *glyphs)
-{
- freetype_get_glyphs(&fontface->IDWriteFontFace5_iface, fontface->charmap, codepoints, count, glyphs);
- return S_OK;
-}
-
static HRESULT WINAPI dwritefontface_GetGlyphIndices(IDWriteFontFace5 *iface, UINT32 const *codepoints,
UINT32 count, UINT16 *glyphs)
{
struct dwrite_fontface *fontface = impl_from_IDWriteFontFace5(iface);
+ unsigned int i;
TRACE("%p, %p, %u, %p.\n", iface, codepoints, count, glyphs);
@@ -755,7 +752,10 @@ static HRESULT WINAPI dwritefontface_GetGlyphIndices(IDWriteFontFace5 *iface, UI
return E_INVALIDARG;
}
- return fontface_get_glyphs(fontface, codepoints, count, glyphs);
+ for (i = 0; i < count; ++i)
+ glyphs[i] = dwritefontface_get_glyph(fontface, codepoints[i]);
+
+ return S_OK;
}
static HRESULT WINAPI dwritefontface_TryGetFontTable(IDWriteFontFace5 *iface, UINT32 table_tag,
@@ -1404,14 +1404,10 @@ static HRESULT WINAPI dwritefontface3_GetInformationalStrings(IDWriteFontFace5 *
static BOOL WINAPI dwritefontface3_HasCharacter(IDWriteFontFace5 *iface, UINT32 ch)
{
struct dwrite_fontface *fontface = impl_from_IDWriteFontFace5(iface);
- UINT16 index;
TRACE("%p, %#x.\n", iface, ch);
- index = 0;
- fontface_get_glyphs(fontface, &ch, 1, &index);
-
- return index != 0;
+ return !!dwritefontface_get_glyph(fontface, ch);
}
static HRESULT WINAPI dwritefontface3_GetRecommendedRenderingMode(IDWriteFontFace5 *iface, FLOAT emSize, FLOAT dpiX, FLOAT dpiY,
@@ -4933,7 +4929,6 @@ HRESULT create_fontface(const struct fontface_desc *desc, struct list *cached_li
}
}
- fontface->charmap = freetype_get_charmap_index(&fontface->IDWriteFontFace5_iface);
if (freetype_has_kerning_pairs(&fontface->IDWriteFontFace5_iface))
fontface->flags |= FONTFACE_HAS_KERNING_PAIRS;
if (opentype_has_vertical_variants(&fontface->IDWriteFontFace5_iface))
@@ -4979,6 +4974,8 @@ HRESULT create_fontface(const struct fontface_desc *desc, struct list *cached_li
if (fontface->info_strings[i])
IDWriteLocalizedStrings_AddRef(fontface->info_strings[i]);
}
+ fontface->cmap.stream = fontface->stream;
+ IDWriteFontFileStream_AddRef(fontface->cmap.stream);
release_font_data(font_data);
fontface->cached = factory_cache_fontface(fontface->factory, cached_list, &fontface->IDWriteFontFace5_iface);
diff --git a/dlls/dwrite/freetype.c b/dlls/dwrite/freetype.c
index 26b0d7bde1e..260d87b7ac6 100644
--- a/dlls/dwrite/freetype.c
+++ b/dlls/dwrite/freetype.c
@@ -52,7 +52,6 @@ static 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_CMapCache cmap_cache = 0;
static FTC_ImageCache image_cache = 0;
typedef struct
{
@@ -83,8 +82,6 @@ MAKE_FUNCPTR(FT_Outline_Get_Bitmap);
MAKE_FUNCPTR(FT_Outline_New);
MAKE_FUNCPTR(FT_Outline_Transform);
MAKE_FUNCPTR(FT_Outline_Translate);
-MAKE_FUNCPTR(FTC_CMapCache_Lookup);
-MAKE_FUNCPTR(FTC_CMapCache_New);
MAKE_FUNCPTR(FTC_ImageCache_Lookup);
MAKE_FUNCPTR(FTC_ImageCache_New);
MAKE_FUNCPTR(FTC_Manager_New);
@@ -206,8 +203,6 @@ BOOL init_freetype(void)
LOAD_FUNCPTR(FT_Outline_New)
LOAD_FUNCPTR(FT_Outline_Transform)
LOAD_FUNCPTR(FT_Outline_Translate)
- LOAD_FUNCPTR(FTC_CMapCache_Lookup)
- LOAD_FUNCPTR(FTC_CMapCache_New)
LOAD_FUNCPTR(FTC_ImageCache_Lookup)
LOAD_FUNCPTR(FTC_ImageCache_New)
LOAD_FUNCPTR(FTC_Manager_New)
@@ -228,7 +223,6 @@ BOOL init_freetype(void)
/* init cache manager */
if (pFTC_Manager_New(library, 0, 0, 0, &face_requester, NULL, &cache_manager) != 0 ||
- pFTC_CMapCache_New(cache_manager, &cmap_cache) != 0 ||
pFTC_ImageCache_New(cache_manager, &image_cache) != 0) {
ERR("Failed to init FreeType cache\n");
@@ -562,27 +556,6 @@ UINT16 freetype_get_glyphcount(IDWriteFontFace5 *fontface)
return count;
}
-void freetype_get_glyphs(IDWriteFontFace5 *fontface, INT charmap, UINT32 const *codepoints, UINT32 count,
- UINT16 *glyphs)
-{
- UINT32 i;
-
- EnterCriticalSection(&freetype_cs);
- for (i = 0; i < count; i++) {
- if (charmap == -1)
- glyphs[i] = pFTC_CMapCache_Lookup(cmap_cache, fontface, charmap, codepoints[i]);
- else {
- UINT32 codepoint = codepoints[i];
- /* special handling for symbol fonts */
- if (codepoint < 0x100) codepoint += 0xf000;
- glyphs[i] = pFTC_CMapCache_Lookup(cmap_cache, fontface, charmap, codepoint);
- if (!glyphs[i])
- glyphs[i] = pFTC_CMapCache_Lookup(cmap_cache, fontface, charmap, codepoint - 0xf000);
- }
- }
- LeaveCriticalSection(&freetype_cs);
-}
-
BOOL freetype_has_kerning_pairs(IDWriteFontFace5 *fontface)
{
BOOL has_kerning_pairs = FALSE;
@@ -841,28 +814,6 @@ BOOL freetype_get_glyph_bitmap(struct dwrite_glyphbitmap *bitmap)
return ret;
}
-INT freetype_get_charmap_index(IDWriteFontFace5 *fontface)
-{
- INT charmap_index = -1;
- FT_Face face;
-
- EnterCriticalSection(&freetype_cs);
- if (pFTC_Manager_LookupFace(cache_manager, fontface, &face) == 0)
- {
- FT_Int i;
-
- for (i = 0; i < face->num_charmaps; i++)
- if (face->charmaps[i]->encoding == FT_ENCODING_MS_SYMBOL)
- {
- charmap_index = i;
- break;
- }
- }
- LeaveCriticalSection(&freetype_cs);
-
- return charmap_index;
-}
-
INT32 freetype_get_glyph_advance(IDWriteFontFace5 *fontface, FLOAT emSize, UINT16 index, DWRITE_MEASURING_MODE mode,
BOOL *has_contours)
{
@@ -923,12 +874,6 @@ UINT16 freetype_get_glyphcount(IDWriteFontFace5 *fontface)
return 0;
}
-void freetype_get_glyphs(IDWriteFontFace5 *fontface, INT charmap, UINT32 const *codepoints, UINT32 count,
- UINT16 *glyphs)
-{
- memset(glyphs, 0, count * sizeof(*glyphs));
-}
-
BOOL freetype_has_kerning_pairs(IDWriteFontFace5 *fontface)
{
return FALSE;
@@ -949,11 +894,6 @@ BOOL freetype_get_glyph_bitmap(struct dwrite_glyphbitmap *bitmap)
return FALSE;
}
-INT freetype_get_charmap_index(IDWriteFontFace5 *fontface)
-{
- return -1;
-}
-
INT32 freetype_get_glyph_advance(IDWriteFontFace5 *fontface, FLOAT emSize, UINT16 index, DWRITE_MEASURING_MODE mode,
BOOL *has_contours)
{
diff --git a/dlls/dwrite/opentype.c b/dlls/dwrite/opentype.c
index 8e507158579..563154992ab 100644
--- a/dlls/dwrite/opentype.c
+++ b/dlls/dwrite/opentype.c
@@ -1728,12 +1728,14 @@ void dwrite_cmap_init(struct dwrite_cmap *cmap, IDWriteFontFile *file, unsigned
if (cmap->data) return;
- if (FAILED(hr = get_filestream_from_file(file, &stream_desc.stream)))
+ /* For fontface stream is already available and preset. */
+ if (!cmap->stream && FAILED(hr = get_filestream_from_file(file, &cmap->stream)))
{
WARN("Failed to get file stream, hr %#x.\n", hr);
goto failed;
}
+ stream_desc.stream = cmap->stream;
stream_desc.face_type = face_type;
stream_desc.face_index = face_index;
--
2.26.2
More information about the wine-devel
mailing list