diff --git a/configure.ac b/configure.ac index 0e962643..1090ebae 100644 --- a/configure.ac +++ b/configure.ac @@ -2000,7 +2000,7 @@ if test "x$build_ttf_support" = "xyes"; then if test "x$build_complex_scripts" = "xyes"; then dnl Check for HarfBuzz library AC_CHECK_LIB(harfbuzz, hb_version, - DEP_LIBS="$DEP_LIBS -lharfbuzz -lfreetype", + DEP_LIBS="$DEP_LIBS -lharfbuzz", build_complex_scripts="no") fi diff --git a/src/font/Makefile.am b/src/font/Makefile.am index b56c9275..ec83f939 100644 --- a/src/font/Makefile.am +++ b/src/font/Makefile.am @@ -16,7 +16,7 @@ SRC_FILES = charset.c charset-arabic.c legacy-bidi.c charset-unicode.c \ unicode-bidi.c \ unicode-break.c \ unicode-joining-types.c unicode-joining.c unicode-shape.c \ - unicode-shape-arabic.c + unicode-shape-arabic.c harzbuff-minigui-funcs.c HDR_FILES = charset.h rawbitmap.h varbitmap.h freetype2.h qpf.h se_minigui.h \ upf.h bitmapfont.h unicode-bidi-tables.h \ diff --git a/src/font/freetype2.c b/src/font/freetype2.c index 87c6eb5f..2ecbf5fa 100644 --- a/src/font/freetype2.c +++ b/src/font/freetype2.c @@ -1147,6 +1147,10 @@ error_ftc_manager: FTC_Manager_Done (ft_cache_manager); #endif /* _MGFONT_TTF_CACHE */ +#ifdef _MGCOMPLEX_SCRIPTS + __mg_init_harzbuff_funcs(); +#endif + return TRUE; error_library: @@ -1171,6 +1175,10 @@ void font_TermFreetypeLibrary (void) FT_Done_FreeType (ft_library); FT_DESTROY_LOCK(&ft_lock); + +#ifdef _MGCOMPLEX_SCRIPTS + __mg_term_harzbuff_funcs(); +#endif } /**************************** Global data ************************************/ diff --git a/src/font/freetype2.h b/src/font/freetype2.h index a3d23256..7fcd96c0 100644 --- a/src/font/freetype2.h +++ b/src/font/freetype2.h @@ -146,6 +146,11 @@ extern void __mg_ttc_sys_deinit(void); extern TTFCACHEINFO *__mg_ttc_search(HCACHE hCache, Glyph32 gv, int *size); extern void __mg_ttc_refer(HCACHE hCache); +#ifdef _MGCOMPLEX_SCRIPTS +extern void __mg_init_harzbuff_funcs(void); +extern void __mg_term_harzbuff_funcs(void); +#endif + #endif #ifdef __cplusplus diff --git a/src/font/harzbuff-minigui-funcs.c b/src/font/harzbuff-minigui-funcs.c new file mode 100644 index 00000000..20c8a7ca --- /dev/null +++ b/src/font/harzbuff-minigui-funcs.c @@ -0,0 +1,157 @@ +/* + * This file is part of MiniGUI, a mature cross-platform windowing + * and Graphics User Interface (GUI) support system for embedded systems + * and smart IoT devices. + * + * Copyright (C) 2002~2018, Beijing FMSoft Technologies Co., Ltd. + * Copyright (C) 1998~2002, WEI Yongming + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Or, + * + * As this program is a library, any link to this program must follow + * GNU General Public License version 3 (GPLv3). If you cannot accept + * GPLv3, you need to be licensed from FMSoft. + * + * If you have got a commercial license of this program, please use it + * under the terms and conditions of the commercial license. + * + * For more information about the commercial license, please refer to + * . + */ + +/* +** harzbuff-minigui-funcs.c: +** +** Functions for using HarfBuzz with the MiniGUI to provide Unicode data. +** +** Create by WEI Yongming at 2019/03/14 +*/ + +#include +#include +#include + +#include "common.h" + +#if defined(_MGCHARSET_UNICODE) && defined(_MGCOMPLEX_SCRIPTS) + +#include "minigui.h" +#include "gdi.h" + +#include + +static hb_unicode_combining_class_t +hb_minigui_unicode_combining_class (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data) + +{ + return (hb_unicode_combining_class_t) UCharCombiningClass (unicode); +} + +static hb_unicode_general_category_t +hb_minigui_unicode_general_category (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data) +{ + /* hb_unicode_general_category_t and GUnicodeType are identical */ + return (hb_unicode_general_category_t) UCharGetCategory (unicode); +} + +static hb_codepoint_t +hb_minigui_unicode_mirroring (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data) +{ + UCharGetMirror (unicode, &unicode); + return unicode; +} + +static hb_script_t +hb_minigui_unicode_script (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t unicode, + void *user_data) +{ + return UCharScriptTypeToISO15924 (UCharGetScriptType(unicode)); +} + +static hb_bool_t +hb_minigui_unicode_compose (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t a, + hb_codepoint_t b, + hb_codepoint_t *ab, + void *user_data) +{ + return UCharCompose (a, b, ab); +} + +static hb_bool_t +hb_minigui_unicode_decompose (hb_unicode_funcs_t *ufuncs, + hb_codepoint_t ab, + hb_codepoint_t *a, + hb_codepoint_t *b, + void *user_data) +{ + return UCharDecompose(ab, a, b); +} + +static hb_unicode_funcs_t *funcs; +static hb_unicode_funcs_t *get_unicode_funcs(void) +{ + 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_minigui_unicode_general_category, NULL, NULL); + hb_unicode_funcs_set_mirroring_func (funcs, + hb_minigui_unicode_mirroring, NULL, NULL); + hb_unicode_funcs_set_script_func (funcs, + hb_minigui_unicode_script, NULL, NULL); + hb_unicode_funcs_set_compose_func (funcs, + hb_minigui_unicode_compose, NULL, NULL); + hb_unicode_funcs_set_decompose_func (funcs, + hb_minigui_unicode_decompose, NULL, NULL); + + hb_unicode_funcs_make_immutable (funcs); + + return funcs; +} + +typedef hb_unicode_funcs_t *(*hb_get_unicode_funcs) (void); +extern hb_get_unicode_funcs __hb_extern_get_unicode_funcs; + +void __mg_init_harzbuff_funcs(void) +{ + _DBG_PRINTF("%s: called\n", __FUNCTION__); + __hb_extern_get_unicode_funcs = get_unicode_funcs; +} + +void __mg_term_harzbuff_funcs(void) +{ + _DBG_PRINTF("%s: called\n", __FUNCTION__); + + if (funcs) { + hb_unicode_funcs_destroy(funcs); + } + else { + _ERR_PRINTF("%s: hb_unicode_funcs_t object is NULL\n", + __FUNCTION__); + } +} + +#endif /* defined(_MGCHARSET_UNICODE) && defined(_MGCOMPLEX_SCRIPTS) */ +