diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c index fd460e5..81de3c1 100644 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c @@ -456,8 +456,8 @@ 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)) @@ -828,7 +828,7 @@ static void viewer_scrollbar(void) { static void viewer_draw(int col) { int i, j, k, line_len, line_width, resynch_move, 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; @@ -902,6 +902,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++; @@ -936,8 +939,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; } } @@ -1025,8 +1032,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; } } @@ -1056,7 +1067,7 @@ static void viewer_draw(int col) *endptr = 0; } } - if (col != -1 && line_width > col) + if (col != -1) #ifdef HAVE_LCD_BITMAP rb->lcd_putsxy(left_col, i*pf->height, utf8_buffer); #else @@ -1389,7 +1400,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; } @@ -1494,7 +1505,7 @@ static void viewer_menu(void) break; } menu_exit(m); - viewer_draw(col); + viewer_draw(cols); } enum plugin_status plugin_start(const struct plugin_api* api, const void* file) @@ -1526,7 +1537,7 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* file) rb->lcd_set_backdrop(NULL); #endif - viewer_draw(col); + viewer_draw(cols); while (!done) { @@ -1535,7 +1546,7 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* file) if(old_tick <= *rb->current_tick - (110-prefs.autoscroll_speed*10)) { viewer_scroll_down(); - viewer_draw(col); + viewer_draw(cols); old_tick = *rb->current_tick; } } @@ -1569,7 +1580,7 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* file) else viewer_scroll_up(); old_tick = *rb->current_tick; - viewer_draw(col); + viewer_draw(cols); break; case VIEWER_PAGE_DOWN: @@ -1583,37 +1594,37 @@ enum plugin_status plugin_start(const struct plugin_api* api, const void* file) else viewer_scroll_down(); 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 @@ -1622,7 +1633,7 @@ enum plugin_status plugin_start(const struct plugin_api* api, 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: @@ -1631,7 +1642,7 @@ enum plugin_status plugin_start(const struct plugin_api* api, 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 @@ -1639,9 +1650,9 @@ enum plugin_status plugin_start(const struct plugin_api* api, 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; @@ -1649,9 +1660,9 @@ enum plugin_status plugin_start(const struct plugin_api* api, 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