mirror of https://github.com/MidnightCommander/mc
Merge branch '1629_nroff_utf8'
* 1629_nroff_utf8: Fixed return codes for mcview_get_utf() function Search does not find text that are bold or underlined (yellow or red) and contain accented letters. Exception: it finds if only the first character is accented, but highlights the match incorrectly. Ticket #1629: Problems displaying UTF-8 manual pages
This commit is contained in:
commit
d7fd84507c
|
@ -164,9 +164,9 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
|
|||
int res = -1;
|
||||
gunichar ch;
|
||||
gchar *next_ch = NULL;
|
||||
int width = 0;
|
||||
|
||||
*result = TRUE;
|
||||
*char_width = 0;
|
||||
*result = FALSE;
|
||||
|
||||
switch (view->datasource)
|
||||
{
|
||||
|
@ -185,18 +185,14 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
|
|||
}
|
||||
|
||||
if (str == NULL)
|
||||
{
|
||||
*result = FALSE;
|
||||
width = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
res = g_utf8_get_char_validated (str, -1);
|
||||
|
||||
if (res < 0)
|
||||
{
|
||||
ch = *str;
|
||||
width = 0;
|
||||
*char_width = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -204,16 +200,11 @@ mcview_get_utf (mcview_t * view, off_t byte_index, int *char_width, gboolean * r
|
|||
/* Calculate UTF-8 char width */
|
||||
next_ch = g_utf8_next_char (str);
|
||||
if (next_ch)
|
||||
{
|
||||
width = next_ch - str;
|
||||
}
|
||||
*char_width = next_ch - str;
|
||||
else
|
||||
{
|
||||
ch = 0;
|
||||
width = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*char_width = width;
|
||||
*result = TRUE;
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,37 @@
|
|||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static gboolean
|
||||
mcview_nroff_get_char (mcview_nroff_t * nroff, int *ret_val, off_t nroff_index)
|
||||
{
|
||||
int c;
|
||||
#ifdef HAVE_CHARSET
|
||||
if (nroff->view->utf8)
|
||||
{
|
||||
gboolean utf_result;
|
||||
c = mcview_get_utf (nroff->view, nroff_index, &nroff->char_width, &utf_result);
|
||||
if (!utf_result)
|
||||
{
|
||||
/* we need got symbol in any case */
|
||||
nroff->char_width = 1;
|
||||
if (!mcview_get_byte (nroff->view, nroff_index, &c) || !g_ascii_isprint (c))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
nroff->char_width = 1;
|
||||
if (!mcview_get_byte (nroff->view, nroff_index, &c))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!g_unichar_isprint (c))
|
||||
return FALSE;
|
||||
*ret_val = c;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -111,10 +142,17 @@ mcview_display_nroff (mcview_t * view)
|
|||
{
|
||||
if (from > 1)
|
||||
{
|
||||
mcview_get_byte (view, from - 2, &c_prev);
|
||||
mcview_get_byte (view, from, &c_next);
|
||||
#ifdef HAVE_CHARSET
|
||||
if (view->utf8)
|
||||
{
|
||||
gboolean read_res;
|
||||
c_next = mcview_get_utf (view, from, &cw, &read_res);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
mcview_get_byte (view, from, &c_next);
|
||||
}
|
||||
if (g_ascii_isprint (c_prev) && g_ascii_isprint (c_prev)
|
||||
if (g_unichar_isprint (c_prev) && g_unichar_isprint (c_next)
|
||||
&& (c_prev == c_next || c_prev == '_' || (c_prev == '+' && c_next == 'o')))
|
||||
{
|
||||
if (col == 0)
|
||||
|
@ -175,6 +213,8 @@ mcview_display_nroff (mcview_t * view)
|
|||
tty_setcolor (SELECTED_COLOR);
|
||||
}
|
||||
|
||||
c_prev = c;
|
||||
|
||||
if ((off_t) col >= view->dpy_text_column
|
||||
&& (off_t) col - view->dpy_text_column < (off_t) width)
|
||||
{
|
||||
|
@ -240,7 +280,7 @@ mcview__get_nroff_real_len (mcview_t * view, off_t start, off_t length)
|
|||
{
|
||||
if (nroff->type != NROFF_TYPE_NONE)
|
||||
{
|
||||
ret += 2;
|
||||
ret += 1 + nroff->char_width;
|
||||
}
|
||||
i++;
|
||||
mcview_nroff_seq_next (nroff);
|
||||
|
@ -298,15 +338,13 @@ mcview_nroff_seq_info (mcview_nroff_t * nroff)
|
|||
return NROFF_TYPE_NONE;
|
||||
nroff->type = NROFF_TYPE_NONE;
|
||||
|
||||
if (!mcview_get_byte (nroff->view, nroff->index, &nroff->current_char) || !g_ascii_isprint (nroff->current_char)) /* FIXME: utf-8 and g_ascii_isprint */
|
||||
if (!mcview_nroff_get_char (nroff, &nroff->current_char, nroff->index))
|
||||
return nroff->type;
|
||||
|
||||
nroff->char_width = 1;
|
||||
|
||||
if (!mcview_get_byte (nroff->view, nroff->index + 1, &next) || next != '\b')
|
||||
if (!mcview_get_byte (nroff->view, nroff->index + nroff->char_width, &next) || next != '\b')
|
||||
return nroff->type;
|
||||
|
||||
if (!mcview_get_byte (nroff->view, nroff->index + 2, &next2) || !g_ascii_isprint (next2)) /* FIXME: utf-8 and g_ascii_isprint */
|
||||
if (!mcview_nroff_get_char (nroff, &next2, nroff->index + 1 + nroff->char_width))
|
||||
return nroff->type;
|
||||
|
||||
if (nroff->current_char == '_' && next2 == '_')
|
||||
|
@ -328,7 +366,6 @@ mcview_nroff_seq_info (mcview_nroff_t * nroff)
|
|||
{
|
||||
/* ??? */
|
||||
}
|
||||
|
||||
return nroff->type;
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,9 @@
|
|||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
static int search_cb_char_curr_index = 0;
|
||||
static char search_cb_char_buffer[6];
|
||||
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
|
@ -168,17 +171,25 @@ mcview_search_cmd_callback (const void *user_data, gsize char_offset)
|
|||
return MC_SEARCH_CB_SKIP;
|
||||
}
|
||||
|
||||
lc_byte = view->search_nroff_seq->current_char;
|
||||
if (search_cb_char_curr_index < view->search_nroff_seq->char_width)
|
||||
{
|
||||
lc_byte = search_cb_char_buffer[search_cb_char_curr_index];
|
||||
search_cb_char_curr_index++;
|
||||
|
||||
if (lc_byte == -1)
|
||||
return MC_SEARCH_CB_INVALID;
|
||||
return (lc_byte != -1) ? lc_byte : MC_SEARCH_CB_INVALID;
|
||||
}
|
||||
|
||||
mcview_nroff_seq_next (view->search_nroff_seq);
|
||||
search_cb_char_curr_index = 0;
|
||||
if (view->search_nroff_seq->char_width > 1)
|
||||
g_unichar_to_utf8 (view->search_nroff_seq->current_char, search_cb_char_buffer);
|
||||
else
|
||||
search_cb_char_buffer[0] = (char) view->search_nroff_seq->current_char;
|
||||
|
||||
if (view->search_nroff_seq->type != NROFF_TYPE_NONE)
|
||||
view->search_numNeedSkipChar = 2;
|
||||
view->search_numNeedSkipChar = 1 + view->search_nroff_seq->char_width;
|
||||
|
||||
return lc_byte;
|
||||
return MC_SEARCH_CB_SKIP;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
|
Loading…
Reference in New Issue