diff --git a/src/font/harzbuff-minigui-funcs.c b/src/font/harzbuff-minigui-funcs.c index 14bc4dc3..4c1c8362 100644 --- a/src/font/harzbuff-minigui-funcs.c +++ b/src/font/harzbuff-minigui-funcs.c @@ -108,27 +108,30 @@ hb_minigui_unicode_decompose (hb_unicode_funcs_t *ufuncs, return UCharDecompose(ab, a, b); } -static hb_unicode_funcs_t *funcs; +static hb_unicode_funcs_t *_funcs; static hb_unicode_funcs_t *get_unicode_funcs(void) { - funcs = hb_unicode_funcs_create (NULL); + if (_funcs) + return _funcs; - hb_unicode_funcs_set_combining_class_func (funcs, + _funcs = hb_unicode_funcs_create (NULL); + + hb_unicode_funcs_set_combining_class_func (_funcs, hb_minigui_unicode_combining_class, NULL, NULL); - hb_unicode_funcs_set_general_category_func (funcs, + hb_unicode_funcs_set_general_category_func (_funcs, hb_minigui_unicode_general_category, NULL, NULL); - hb_unicode_funcs_set_mirroring_func (funcs, + hb_unicode_funcs_set_mirroring_func (_funcs, hb_minigui_unicode_mirroring, NULL, NULL); - hb_unicode_funcs_set_script_func (funcs, + hb_unicode_funcs_set_script_func (_funcs, hb_minigui_unicode_script, NULL, NULL); - hb_unicode_funcs_set_compose_func (funcs, + hb_unicode_funcs_set_compose_func (_funcs, hb_minigui_unicode_compose, NULL, NULL); - hb_unicode_funcs_set_decompose_func (funcs, + hb_unicode_funcs_set_decompose_func (_funcs, hb_minigui_unicode_decompose, NULL, NULL); - hb_unicode_funcs_make_immutable (funcs); + hb_unicode_funcs_make_immutable (_funcs); - return funcs; + return _funcs; } typedef hb_unicode_funcs_t *(*hb_get_unicode_funcs) (void); @@ -144,8 +147,8 @@ void __mg_term_harzbuff_funcs(void) { _DBG_PRINTF("%s: called\n", __FUNCTION__); - if (funcs) { - hb_unicode_funcs_destroy(funcs); + if (_funcs) { + hb_unicode_funcs_destroy(_funcs); } else { _ERR_PRINTF("%s: hb_unicode_funcs_t object is NULL\n", diff --git a/src/newgdi/layout.c b/src/newgdi/layout.c index c17b6a20..cd7673b4 100644 --- a/src/newgdi/layout.c +++ b/src/newgdi/layout.c @@ -211,8 +211,9 @@ BOOL GUIAPI DestroyLayout(LAYOUT* layout) { if (layout->lf_upright) { FONT_RES* font_res = (FONT_RES*)layout->lf_upright; - if (font_res->key) + if (font_res->key) { ReleaseRes(font_res->key); + } } while (!list_empty(&layout->lines)) { diff --git a/src/newgdi/shape-glyphs-complex.c b/src/newgdi/shape-glyphs-complex.c index ba408033..188b3423 100644 --- a/src/newgdi/shape-glyphs-complex.c +++ b/src/newgdi/shape-glyphs-complex.c @@ -63,13 +63,16 @@ #include #include +// define _CACHED_HB_FONT if you want use the cached HB fonts +#define _CACHED_HB_FONT 1 + typedef struct _FtFontInfo { struct list_head list; LOGFONT* lf; ScriptType st; FT_Face face; hb_font_t* hb_font; - //hb_face_t* hb_face; + hb_face_t* hb_face; int dfi; } FtFontInfo; @@ -79,13 +82,15 @@ struct _SEInstance { struct list_head cached_fonts; }; +#ifdef _CACHED_HB_FONT + static hb_font_t* get_hb_font_for_script(SEInstance* inst, LOGFONT* lf, ScriptType st, Uchar32 uc, int* dfi) { struct list_head* f; const FT2INFO* file_face; hb_font_t* hb_font; - //hb_face_t* hb_face; + hb_face_t* hb_face; FtFontInfo *new_fi; FONT_RES* font_res; @@ -105,19 +110,19 @@ static hb_font_t* get_hb_font_for_script(SEInstance* inst, return NULL; } - hb_font = hb_ft_font_create_referenced(file_face->face); + hb_face = hb_ft_face_create_cached(file_face->face); + hb_font = hb_font_create(hb_face); + //hb_font = hb_ft_font_create_referenced(file_face->face); //hb_font = hb_ft_font_create(face, NULL); if (hb_font == NULL) return NULL; - //hb_face = hb_face_reference (hb_font_get_face (hb_font)); - new_fi = mg_slice_new(FtFontInfo); new_fi->lf = lf; new_fi->st = st; new_fi->face = file_face->face; new_fi->hb_font = hb_font; - //new_fi->hb_face = hb_face; + new_fi->hb_face = hb_face; new_fi->dfi = *dfi; font_res = (FONT_RES*)lf; @@ -128,6 +133,8 @@ static hb_font_t* get_hb_font_for_script(SEInstance* inst, return hb_font; } +#endif /* _CACHED_HB_FONT */ + static SEInstance* create_instance(void) { SEInstance* inst; @@ -159,8 +166,8 @@ static BOOL destroy_instance(SEInstance* inst) FtFontInfo *fi = (FtFontInfo*)inst->cached_fonts.prev; list_del(inst->cached_fonts.prev); - //hb_face_destroy(fi->hb_face); hb_font_destroy(fi->hb_font); + hb_face_destroy(fi->hb_face); font_res = (FONT_RES*)fi->lf; if (font_res->key) { @@ -185,6 +192,9 @@ static BOOL shape_layout_run(SEInstance* inst, int dfi; unsigned int i, nr_glyphs; hb_buffer_t *hb_buf = NULL; +#ifndef _CACHED_HB_FONT + hb_face_t *hb_face = NULL; +#endif hb_font_t *hb_font = NULL; hb_glyph_info_t *glyph_info; hb_glyph_position_t *glyph_pos; @@ -203,10 +213,26 @@ static BOOL shape_layout_run(SEInstance* inst, hb_buffer_set_script(hb_buf, ScriptTypeToISO15924(run->st)); hb_buffer_set_language(hb_buf, hb_language_from_string(LanguageCodeToISO639s1(run->lc), -1)); + hb_buffer_set_cluster_level(hb_buf, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS); + hb_buffer_set_flags(hb_buf, HB_BUFFER_FLAG_BOT | HB_BUFFER_FLAG_EOT); +#ifdef _CACHED_HB_FONT hb_font = get_hb_font_for_script(inst, run->lf, run->st, run->ucs[0], &dfi); if (hb_font == NULL) goto error; +#else + { + const FT2INFO* file_face; + file_face = __mg_ft2_get_face(run->lf, run->ucs[0], &dfi); + if (file_face == NULL) { + _WRN_PRINTF("Cannot get FT2 face for logfont (%p) and uc (0x%x)\n", + run->lf, run->ucs[0]); + return FALSE; + } + hb_face = hb_ft_face_create_cached(file_face->face); + hb_font = hb_font_create(hb_face); + } +#endif hb_shape(hb_font, hb_buf, NULL, 0); @@ -219,6 +245,9 @@ static BOOL shape_layout_run(SEInstance* inst, } // generate result + assert(gs->glyphs == NULL); + assert(gs->log_clusters == NULL); + gs->glyphs = malloc(sizeof(ShapedGlyph) * nr_glyphs); if (gs->glyphs == NULL) { goto error; @@ -264,6 +293,13 @@ error: if (hb_buf) hb_buffer_destroy(hb_buf); +#ifndef _CACHED_HB_FONT + if (hb_font) + hb_font_destroy(hb_font); + if (hb_face) + hb_face_destroy(hb_face); +#endif + return ok; }