diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c index 508b594..73a2760 100755 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c @@ -585,8 +585,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)) @@ -1091,7 +1091,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; @@ -1152,6 +1152,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++; @@ -1186,8 +1189,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; } } @@ -1275,8 +1282,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; } } @@ -1306,7 +1317,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); @@ -2249,7 +2260,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; } @@ -2512,7 +2523,7 @@ static void viewer_menu(void) } 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) @@ -2550,7 +2561,7 @@ enum plugin_status plugin_start(const void* file) rb->lcd_set_backdrop(NULL); #endif - viewer_draw(col); + viewer_draw(cols); while (!done) { @@ -2559,7 +2570,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; } } @@ -2597,7 +2608,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: @@ -2615,37 +2626,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 @@ -2654,7 +2665,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: @@ -2663,7 +2674,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 @@ -2671,9 +2682,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; @@ -2681,9 +2692,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 @@ -2715,7 +2726,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;