diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c index dc61a3d..4a8a907 100644 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c @@ -581,8 +581,8 @@ static unsigned char* get_ucs(const unsigned char* str, unsigned short* ch) return (unsigned char*)str+2; } -bool done = false; -int col = 0; +static bool done = false; +static int cols = 0; #define ADVANCE_COUNTERS(c) { width += glyph_width(c); k++; } #define LINE_IS_FULL ((k>=MAX_COLUMNS-1) ||( width >= draw_columns)) @@ -1087,7 +1087,7 @@ static void viewer_show_footer(void) static void viewer_draw(int col) { int i, j, k, line_len, line_width, spaces, left_col=0; - int width, extra_spaces, indent_spaces, spaces_per_word; + int width, extra_spaces, indent_spaces, spaces_per_word, nc; bool multiple_spacing, line_is_short; unsigned short ch; unsigned char *str, *oldstr; @@ -1148,6 +1148,9 @@ static void viewer_draw(int col) line_width += glyph_width(ch); } + endptr = utf8_buffer; + nc = draw_columns/glyph_width('i'); + if (prefs.line_mode == JOIN) { if (line_begin[0] == 0) { line_begin++; @@ -1182,8 +1185,12 @@ static void viewer_draw(int col) } if (col != -1) { scratch_buffer[k] = 0; - endptr = rb->iso_decode(scratch_buffer + col, utf8_buffer, - prefs.encoding, draw_columns/glyph_width('i')); + if (col > 0 && k >= nc) + endptr = rb->iso_decode(scratch_buffer + nc, utf8_buffer, + prefs.encoding, k - nc); + else if (col == 0) + endptr = rb->iso_decode(scratch_buffer, utf8_buffer, + prefs.encoding, nc); *endptr = 0; } } @@ -1271,8 +1278,12 @@ static void viewer_draw(int col) if (col != -1) { scratch_buffer[k] = 0; - endptr = rb->iso_decode(scratch_buffer + col, utf8_buffer, - prefs.encoding, k-col); + if (col > 0 && k >= nc) + endptr = rb->iso_decode(scratch_buffer + nc, utf8_buffer, + prefs.encoding, k - nc); + else if (col == 0) + endptr = rb->iso_decode(scratch_buffer, utf8_buffer, + prefs.encoding, nc); *endptr = 0; } } @@ -1302,7 +1313,7 @@ static void viewer_draw(int col) *endptr = 0; } } - if (col != -1 && line_width > col) + if (col != -1) { int dpage = (cline+i <= display_lines)?cpage:cpage+1; int dline = cline+i - ((cline+i <= display_lines)?0:display_lines); @@ -2245,7 +2256,7 @@ static bool view_mode_setting(void) ret = rb->set_option("Wide View", &prefs.view_mode, INT, names , 2, NULL); if (prefs.view_mode == NARROW) - col = 0; + cols = 0; return ret; } @@ -2504,7 +2515,7 @@ static void viewer_menu(void) menu_exit(m); if (!done && rb->strcmp(prefs.font, sys_font)) set_font(prefs.font); - viewer_draw(col); + viewer_draw(cols); } enum plugin_status plugin_start(const void* file) @@ -2542,7 +2553,7 @@ enum plugin_status plugin_start(const void* file) rb->lcd_set_backdrop(NULL); #endif - viewer_draw(col); + viewer_draw(cols); while (!done) { @@ -2551,7 +2562,7 @@ enum plugin_status plugin_start(const void* file) if(old_tick <= *rb->current_tick - (110-prefs.autoscroll_speed*10)) { viewer_scroll_down(true); - viewer_draw(col); + viewer_draw(cols); old_tick = *rb->current_tick; } } @@ -2589,7 +2600,7 @@ enum plugin_status plugin_start(const void* file) else viewer_scroll_up(); old_tick = *rb->current_tick; - viewer_draw(col); + viewer_draw(cols); break; case VIEWER_PAGE_DOWN: @@ -2607,37 +2618,37 @@ enum plugin_status plugin_start(const void* file) else viewer_scroll_down(autoscroll); old_tick = *rb->current_tick; - viewer_draw(col); + viewer_draw(cols); break; case VIEWER_SCREEN_LEFT: case VIEWER_SCREEN_LEFT | BUTTON_REPEAT: if (prefs.view_mode == WIDE) { /* Screen left */ - col -= draw_columns; - col = col_limit(col); + cols -= draw_columns; + cols = col_limit(cols); } else { /* prefs.view_mode == NARROW */ /* Top of file */ viewer_top(); } - viewer_draw(col); + viewer_draw(cols); break; case VIEWER_SCREEN_RIGHT: case VIEWER_SCREEN_RIGHT | BUTTON_REPEAT: if (prefs.view_mode == WIDE) { /* Screen right */ - col += draw_columns; - col = col_limit(col); + cols += draw_columns; + cols = col_limit(cols); } else { /* prefs.view_mode == NARROW */ /* Bottom of file */ viewer_bottom(); } - viewer_draw(col); + viewer_draw(cols); break; #ifdef VIEWER_LINE_UP @@ -2646,7 +2657,7 @@ enum plugin_status plugin_start(const void* file) /* Scroll up one line */ viewer_scroll_up(); old_tick = *rb->current_tick; - viewer_draw(col); + viewer_draw(cols); break; case VIEWER_LINE_DOWN: @@ -2655,7 +2666,7 @@ enum plugin_status plugin_start(const void* file) if (next_screen_ptr != NULL) screen_top_ptr = next_line_ptr; old_tick = *rb->current_tick; - viewer_draw(col); + viewer_draw(cols); break; #endif #ifdef VIEWER_COLUMN_LEFT @@ -2663,9 +2674,9 @@ enum plugin_status plugin_start(const void* file) case VIEWER_COLUMN_LEFT | BUTTON_REPEAT: if (prefs.view_mode == WIDE) { /* Scroll left one column */ - col -= glyph_width('o'); - col = col_limit(col); - viewer_draw(col); + cols -= glyph_width('o'); + cols = col_limit(cols); + viewer_draw(cols); } break; @@ -2673,9 +2684,9 @@ enum plugin_status plugin_start(const void* file) case VIEWER_COLUMN_RIGHT | BUTTON_REPEAT: if (prefs.view_mode == WIDE) { /* Scroll right one column */ - col += glyph_width('o'); - col = col_limit(col); - viewer_draw(col); + cols += glyph_width('o'); + cols = col_limit(cols); + viewer_draw(cols); } break; #endif @@ -2707,7 +2718,7 @@ enum plugin_status plugin_start(const void* file) viewer_remove_bookmark(idx); rb->splash(HZ/2, "Bookmark remove."); } - viewer_draw(col); + viewer_draw(cols); } break;