fix bug: not convert AChar to Glyph32

This commit is contained in:
Vincent Wei
2019-03-29 20:18:26 +08:00
parent 2f52006cde
commit 61b799af88
4 changed files with 84 additions and 52 deletions
+37 -30
View File
@@ -296,33 +296,36 @@ load_or_search_glyph (FTINSTANCEINFO* ft_inst_info, FT_Face* face,
*face = ft_face_info->face;
ft_inst_info->cur_index = gv;
if (FT_Load_Glyph (*face, ft_inst_info->cur_index, ft_load_flags)) {
_WRN_PRINTF ("FONT>FT2: FT_Load_Glyph error\n");
_WRN_PRINTF ("FONT>FT2: FT_Load_Glyph error");
return -1;
}
if (FT_Get_Glyph ((*face)->glyph, &(ft_inst_info->glyph))) {
_WRN_PRINTF ("FONT>FT2: FT_Get_Glyph error\n");
_WRN_PRINTF ("FONT>FT2: FT_Get_Glyph error");
return -1;
}
#else /* !_MGFONT_TTF_CACHE */
FT_Error error;
FT_Glyph ft_glyph_tmp;
if (get_cached_face (ft_inst_info, face)) {
_WRN_PRINTF ("FONT>FT2: can't access font file %p\n", face);
_WRN_PRINTF ("FONT>FT2: can't access font file %p", face);
return 0;
}
ft_inst_info->cur_index = gv;
if (FTC_ImageCache_Lookup (ft_image_cache, &ft_inst_info->image_type,
ft_inst_info->cur_index, &ft_glyph_tmp, NULL)) {
_WRN_PRINTF ("FONT>FT2: can't access image cache.\n");
if ((error = FTC_ImageCache_Lookup (ft_image_cache, &ft_inst_info->image_type,
ft_inst_info->cur_index, &ft_glyph_tmp, NULL))) {
_WRN_PRINTF ("FONT>FT2: can't access image cache for index: 0x%X: %X",
ft_inst_info->cur_index, error);
assert(0);
return -1;
}
if (FT_Glyph_Copy (ft_glyph_tmp, &ft_inst_info->glyph)) {
_WRN_PRINTF ("FONT>FT2: can't copy glyph from cache.\n");
_WRN_PRINTF ("FONT>FT2: can't copy glyph from cache.");
return -1;
}
@@ -379,7 +382,8 @@ get_glyph_bbox (LOGFONT* logfont, DEVFONT* devfont, Glyph32 gv,
if (load_or_search_glyph (ft_inst_info, &face, gv,
get_glyph_bmptype(logfont, devfont))) {
_ERR_PRINTF ("FONT>FT2: load_or_search_glyph error in freetype2\n");
_ERR_PRINTF ("%s: load_or_search_glyph error in freetype2\n",
__FUNCTION__);
goto error;
}
@@ -522,7 +526,8 @@ char_bitmap_pixmap (LOGFONT* logfont, DEVFONT* devfont,
if (load_or_search_glyph (ft_inst_info, &face, gv,
get_glyph_bmptype(logfont, devfont))) {
_ERR_PRINTF ("FONT>FT2: load_or_search_glyph failed in freetype2\n");
_ERR_PRINTF ("%s: load_or_search_glyph failed in freetype2\n",
__FUNCTION__);
goto error;
}
@@ -532,7 +537,8 @@ char_bitmap_pixmap (LOGFONT* logfont, DEVFONT* devfont,
IS_SUBPIXEL(logfont) && is_grey) {
if (FT_Glyph_To_Bitmap (&(ft_inst_info->glyph),
FT_RENDER_MODE_LCD, NULL, 1)) {
_ERR_PRINTF ("FONT>FT2: FT_Glyph_To_Bitmap failed\n");
_ERR_PRINTF ("%s: FT_Glyph_To_Bitmap failed\n",
__FUNCTION__);
goto error;
}
}
@@ -540,7 +546,8 @@ char_bitmap_pixmap (LOGFONT* logfont, DEVFONT* devfont,
if (FT_Glyph_To_Bitmap (&(ft_inst_info->glyph),
is_grey ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO,
NULL, 1)) {
_ERR_PRINTF ("FONT>FT2: FT_Glyph_To_Bitmap failed\n");
_ERR_PRINTF ("%s: FT_Glyph_To_Bitmap failed\n",
__FUNCTION__);
goto error;
}
}
@@ -711,7 +718,8 @@ get_glyph_advance (LOGFONT* logfont, DEVFONT* devfont,
if (load_or_search_glyph (ft_inst_info, &face, gv,
get_glyph_bmptype(logfont, devfont))) {
_ERR_PRINTF ("FONT>FT2: load_or_search_glyph error in freetype2\n");
_ERR_PRINTF ("%s: load_or_search_glyph error in freetype2\n",
__FUNCTION__);
goto error;
}
@@ -854,7 +862,7 @@ new_instance (LOGFONT* logfont, DEVFONT* devfont, BOOL need_sbc_font)
if (FTC_Manager_LookupFace (ft_cache_manager,
(FTC_FaceID)ft_face_info, &face)) {
/* can't access the font file. do not render anything */
_WRN_PRINTF ("FONT>FT2: can't access font file %p\n", ft_face_info);
_WRN_PRINTF ("can't access font file %p", ft_face_info);
goto out_lock;
}
#else
@@ -1023,7 +1031,7 @@ static Glyph32 get_glyph_value (LOGFONT* logfont, DEVFONT* devfont, Achar32 ac)
gv = FT_Get_Char_Index (face, uc);
#else /* !_MGFONT_TTF_CACHE */
if (get_cached_face (ft_inst_info, &face)) {
_WRN_PRINTF ("FONT>FT2: can't access cached face %p\n", ft_inst_info->ft_face_info);
_WRN_PRINTF ("can't access cached face %p", ft_inst_info->ft_face_info);
goto error;
}
@@ -1081,12 +1089,12 @@ static void* load_font_data (DEVFONT* devfont,
#endif
if (error == FT_Err_Unknown_File_Format) {
_ERR_PRINTF ("FONT>FT2: bad file format: %s\n", file_name);
_ERR_PRINTF ("%s: bad file format: %s\n", __FUNCTION__, file_name);
goto error;
}
else if (error) {
_ERR_PRINTF ("FONT>FT2: failed to open the font file: %s (%d)\n",
file_name, error);
_ERR_PRINTF ("%s: failed to open the font file: %s (%d)\n",
__FUNCTION__, file_name, error);
goto error;
}
@@ -1100,8 +1108,8 @@ static void* load_font_data (DEVFONT* devfont,
&& (charmap->encoding_id == TT_APPLE_ID_DEFAULT))) {
error = FT_Set_Charmap (face, charmap);
if (error) {
_ERR_PRINTF ("FONT>FT2: can not set UNICODE CharMap (%d)\n",
error);
_ERR_PRINTF ("%s: can not set UNICODE CharMap (%d)\n",
__FUNCTION__, error);
goto error;
}
#ifdef _MGFONT_TTF_CACHE
@@ -1112,7 +1120,7 @@ static void* load_font_data (DEVFONT* devfont,
}
if (i == face->num_charmaps) {
_ERR_PRINTF ("FONT>FT2: No UNICODE CharMap: %s\n", file_name);
_ERR_PRINTF ("%s: No UNICODE CharMap: %s\n", __FUNCTION__, file_name);
goto error;
}
@@ -1184,12 +1192,11 @@ static void unload_font_data (DEVFONT* devfont, void* data)
free(ft_data);
}
static void ShowErr (const char* message , int error)
static void ShowErr (const char* func, const char* message, int error)
{
_ERR_PRINTF ("FONT>FT2: %s\n error = 0x%04x\n", message, error );
_ERR_PRINTF ("%s: %s (error = 0x%04x)\n", func, message, error );
}
/******************************* Global data ********************************/
BOOL font_InitFreetypeLibrary (void)
{
@@ -1206,7 +1213,7 @@ BOOL font_InitFreetypeLibrary (void)
/* Init freetype library */
error = FT_Init_FreeType (&ft_library);
if (error) {
ShowErr ("could not initialize FreeType 2 library", error);
ShowErr (__FUNCTION__, "could not initialize FreeType 2 library", error);
goto error_library;
}
@@ -1217,32 +1224,32 @@ BOOL font_InitFreetypeLibrary (void)
error = FTC_Manager_New (ft_library, 0, 0, 0,
my_face_requester, 0, &ft_cache_manager);
if (error) {
ShowErr ("could not initialize cache manager", error);
ShowErr (__FUNCTION__, "could not initialize cache manager", error);
goto error_ftc_manager;
}
error = FTC_ImageCache_New (ft_cache_manager, &ft_image_cache);
if (error) {
ShowErr ("could not initialize glyph image cache", error);
ShowErr (__FUNCTION__, "could not initialize glyph image cache", error);
goto error_ftc_manager;
}
error = FTC_CMapCache_New (ft_cache_manager, &ft_cmap_cache);
if (error) {
ShowErr ("could not initialize charmap cache", error);
ShowErr (__FUNCTION__, "could not initialize charmap cache", error);
goto error_ftc_manager;
}
#if 0
error = FTC_SBitCache_New(ft_cache_manager, &ft_sbit_cache);
if (error) {
ShowErr ("could not initialize sbit cache", error);
ShowErr (__FUNCTION__, "could not initialize sbit cache", error);
goto error_ftc_manager;
}
#endif
if (__mg_ttc_sys_init (_MGMAX_TTF_CACHE, _MGTTF_CACHE_SIZE * 1024)) {
_WRN_PRINTF ("FONT>FT2: init ttf cache sys failed\n");
_WRN_PRINTF ("init ttf cache sys failed");
goto error_library;
}
@@ -1265,7 +1272,7 @@ error_ftc_manager:
return TRUE;
error_library:
_ERR_PRINTF ("FONT>FT2: Could not initialise FreeType 2 library\n");
_ERR_PRINTF ("%s: Could not initialise FreeType 2 library\n", __FUNCTION__);
FT_DESTROY_LOCK(&ft_lock);
FT_Done_FreeType (ft_library);
+3 -5
View File
@@ -243,7 +243,6 @@ static const void* get_glyph_monobitmap (LOGFONT* logfont, DEVFONT* devfont,
Glyph32 glyph_value, SIZE* sz, int* pitch, unsigned short* scale)
{
int offset;
Glyph32 eff_value;
Glyph32 first_value;
Glyph32 last_value;
VBFINFO* vbf_info = VARFONT_INFO_P (devfont);
@@ -252,15 +251,14 @@ static const void* get_glyph_monobitmap (LOGFONT* logfont, DEVFONT* devfont,
last_value = vbf_info->last_glyph;
glyph_value = REAL_GLYPH(glyph_value);
eff_value = glyph_value;
if (glyph_value < first_value || glyph_value > last_value)
eff_value = vbf_info->def_glyph;
glyph_value = vbf_info->def_glyph;
if (vbf_info->bits_offset == NULL)
offset = (((size_t)vbf_info->max_width + 7) >> 3) * vbf_info->height
* (eff_value - first_value);
* (glyph_value - first_value);
else {
offset = vbf_info->bits_offset [eff_value - vbf_info->first_glyph];
offset = vbf_info->bits_offset [glyph_value - vbf_info->first_glyph];
#if MGUI_BYTEORDER == MGUI_BIG_ENDIAN
if (vbf_info->font_size)
offset = ArchSwap16 (offset);
+2 -1
View File
@@ -2635,7 +2635,8 @@ static void draw_glyph_lines (PDC pdc, int x1, int y1, int x2, int y2)
_dc_set_pixel_noclip);
}
else
_WRN_PRINTF ("no under line, rc_output: %d, %d, %d, %d\n",
_DBG_PRINTF ("%s: no under line, rc_output: %d, %d, %d, %d\n",
__FUNCTION__,
pdc->rc_output.left, pdc->rc_output.top,
pdc->rc_output.right, pdc->rc_output.bottom);
cliprect = cliprect->next;
+42 -16
View File
@@ -191,7 +191,7 @@ static int output_visual_achars_ltr (PDC pdc, Achar32* visual_achars,
if ((gv = GetGlyphValue(pdc->pLogFont, chv)) == INV_GLYPH_VALUE) {
_DBG_PRINTF("%s: got a bad glyph value from achar: %x\n",
__FUNCTION__, chv);
goto end ;
goto end;
}
if (!cb_one_glyph (context, gv, char_type)) {
@@ -214,7 +214,7 @@ static int output_visual_achars_ltr (PDC pdc, Achar32* visual_achars,
INV_GLYPH_VALUE) {
_DBG_PRINTF("%s: got a bad glyph value from achar: %x\n",
__FUNCTION__, biggest_vowel);
goto end ;
goto end;
}
if (!cb_one_glyph (context, gv, char_type)){
@@ -446,6 +446,7 @@ static int _gdi_output_achars_direct(PDC pdc, const unsigned char* text,
{
unsigned int char_type;
Achar32 chv;
Glyph32 gv;
DEVFONT* sbc_devfont = pdc->pLogFont->devfonts[0];
DEVFONT* mbc_devfont = pdc->pLogFont->devfonts[1];
int len_cur_char = 0;
@@ -464,7 +465,7 @@ static int _gdi_output_achars_direct(PDC pdc, const unsigned char* text,
#endif
while (left_bytes > 0){
if(mbc_devfont){
if (mbc_devfont) {
len_cur_char = mbc_devfont->charset_ops->len_first_char
((const unsigned char*)text, left_bytes);
if (len_cur_char > 0) {
@@ -483,7 +484,8 @@ static int _gdi_output_achars_direct(PDC pdc, const unsigned char* text,
chv = sbc_devfont->charset_ops->get_char_value
(NULL, 0, text, left_bytes);
}
else break;
else
break;
do_glyph:
if (IS_MBCHV (chv))
@@ -491,7 +493,12 @@ do_glyph:
else
char_type = sbc_devfont->charset_ops->char_type (chv);
if(if_break){
gv = GetGlyphValue(pdc->pLogFont, chv);
if (gv == INV_GLYPH_VALUE) {
continue;
}
if (if_break) {
DRAWTEXTEX2_CTXT _txt;
_txt.pdc = pdc;
_txt.x = 0;
@@ -500,17 +507,17 @@ do_glyph:
_txt.nFormat = ctxt->nFormat;
_txt.only_extent = TRUE;
_txt.tab_width = ctxt->tab_width;
if (!cb_one_glyph(&_txt, chv, char_type)){
if (!cb_one_glyph(&_txt, gv, char_type)) {
break;
}
line_width += _txt.advance;
if(line_width > ctxt->max_extent){
if (line_width > ctxt->max_extent) {
break;
}
}
if(if_draw) {
if (!cb_one_glyph(ctxt, chv, char_type)){
if (if_draw) {
if (!cb_one_glyph(ctxt, gv, char_type)){
break;
}
}
@@ -522,8 +529,8 @@ do_glyph:
ctxt->nCount = text_len - left_bytes;
}
}
return i;
return i;
}
Achar32* _gdi_bidi_reorder (PDC pdc, const unsigned char* text, int text_len,
@@ -587,19 +594,27 @@ int _gdi_reorder_text (PDC pdc, const unsigned char* text, int text_len,
else {
if (!direction) { /* right to left, reverse text.*/
for (i = text_len - 1; i >= 0; i--) {
Glyph32 gv;
if (!(chv = sbc_devfont->charset_ops->get_char_value
(NULL, 0, text + i, 1)))
(NULL, 0, text + i, 1)))
return (text_len-i-1);
char_type = sbc_devfont->charset_ops->char_type
(chv);
if (!cb_one_glyph (context, chv, char_type))
gv = GetGlyphValue (pdc->pLogFont, chv);
if (gv == INV_GLYPH_VALUE)
continue;
if (!cb_one_glyph (context, gv, char_type))
break;
}
}
else {
for (i = 0; i < text_len; i++) {
Glyph32 gv;
if (!(chv = sbc_devfont->charset_ops->get_char_value
(NULL, 0, text + i, 1)))
return i;
@@ -607,7 +622,11 @@ int _gdi_reorder_text (PDC pdc, const unsigned char* text, int text_len,
char_type = sbc_devfont->charset_ops->char_type
(chv);
if(!cb_one_glyph (context, chv, char_type))
gv = GetGlyphValue (pdc->pLogFont, chv);
if (gv == INV_GLYPH_VALUE)
continue;
if (!cb_one_glyph (context, gv, char_type))
break;
}
}
@@ -638,6 +657,8 @@ _gdi_get_achars_string_charbreak(PDC pdc, const unsigned char* text,
logical_achars = malloc(text_len * sizeof (Achar32));
while (left_bytes > 0){
Glyph32 gv;
if (mbc_devfont) {
len_cur_char = mbc_devfont->charset_ops->len_first_char
((const unsigned char*)text, left_bytes);
@@ -661,7 +682,8 @@ _gdi_get_achars_string_charbreak(PDC pdc, const unsigned char* text,
prev_len += len_cur_char;
}
line_width += _gdi_get_glyph_advance (pdc, logical_achars[i-1],
gv = GetGlyphValue(pdc->pLogFont, chv);
line_width += _gdi_get_glyph_advance (pdc, gv,
TRUE, 0, 0, NULL, NULL, &bbox);
left_bytes -= len_cur_char;
text += len_cur_char;
@@ -674,7 +696,9 @@ _gdi_get_achars_string_charbreak(PDC pdc, const unsigned char* text,
chv = sbc_devfont->charset_ops->get_char_value
(NULL, 0, text, left_bytes);
logical_achars[i++] = chv;
line_width += _gdi_get_glyph_advance (pdc, logical_achars[i-1],
gv = GetGlyphValue(pdc->pLogFont, chv);
line_width += _gdi_get_glyph_advance (pdc, gv,
TRUE, 0, 0, NULL, NULL, &bbox);
left_bytes -= len_cur_char;
text += len_cur_char;
@@ -910,13 +934,15 @@ _gdi_output_achars_direct_sbc_rtol_break(PDC pdc, const unsigned char* text,
if(ctxt->nCount <= 0) return 0;
for (i = ctxt->nCount - 1; i >= 0; i--) {
Glyph32 gv;
chv = sbc_devfont->charset_ops->get_char_value
(NULL, 0, text + i, 1);
char_type = sbc_devfont->charset_ops->char_type
(chv);
if(!cb_one_glyph (context, chv, char_type))
gv = GetGlyphValue(pdc->pLogFont, chv);
if (!cb_one_glyph (context, gv, char_type))
break;
}
return nr_achars;