diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/viewer.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c index 929a2c0ee1..e8d6116eb6 100644 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c | |||
@@ -635,6 +635,7 @@ static int bookmark_count; | |||
635 | 635 | ||
636 | static bool is_bom = false; | 636 | static bool is_bom = false; |
637 | 637 | ||
638 | /* calculate the width of a UCS character (zero width for diacritics) */ | ||
638 | static int glyph_width(int ch) | 639 | static int glyph_width(int ch) |
639 | { | 640 | { |
640 | if (ch == 0) | 641 | if (ch == 0) |
@@ -647,6 +648,7 @@ static int glyph_width(int ch) | |||
647 | #endif | 648 | #endif |
648 | } | 649 | } |
649 | 650 | ||
651 | /* get UCS character from string */ | ||
650 | static unsigned char* get_ucs(const unsigned char* str, unsigned short* ch) | 652 | static unsigned char* get_ucs(const unsigned char* str, unsigned short* ch) |
651 | { | 653 | { |
652 | unsigned char utf8_tmp[6]; | 654 | unsigned char utf8_tmp[6]; |
@@ -659,6 +661,7 @@ static unsigned char* get_ucs(const unsigned char* str, unsigned short* ch) | |||
659 | rb->iso_decode(str, utf8_tmp, prefs.encoding, count); | 661 | rb->iso_decode(str, utf8_tmp, prefs.encoding, count); |
660 | rb->utf8decode(utf8_tmp, ch); | 662 | rb->utf8decode(utf8_tmp, ch); |
661 | 663 | ||
664 | /* return a pointer after the parsed section of the string */ | ||
662 | #ifdef HAVE_LCD_BITMAP | 665 | #ifdef HAVE_LCD_BITMAP |
663 | if (prefs.encoding >= SJIS && *str >= 0x80 | 666 | if (prefs.encoding >= SJIS && *str >= 0x80 |
664 | && !(prefs.encoding == SJIS && *str > 0xA0 && *str < 0xE0)) | 667 | && !(prefs.encoding == SJIS && *str > 0xA0 && *str < 0xE0)) |
@@ -668,6 +671,7 @@ static unsigned char* get_ucs(const unsigned char* str, unsigned short* ch) | |||
668 | return (unsigned char*)str+1; | 671 | return (unsigned char*)str+1; |
669 | } | 672 | } |
670 | 673 | ||
674 | /* decode UCS string into UTF-8 string */ | ||
671 | static unsigned char *decode2utf8(const unsigned char *src, unsigned char *dst, | 675 | static unsigned char *decode2utf8(const unsigned char *src, unsigned char *dst, |
672 | int skip_width, int disp_width) | 676 | int skip_width, int disp_width) |
673 | { | 677 | { |
@@ -677,6 +681,7 @@ static unsigned char *decode2utf8(const unsigned char *src, unsigned char *dst, | |||
677 | unsigned char *utf8 = dst; | 681 | unsigned char *utf8 = dst; |
678 | int width = 0; | 682 | int width = 0; |
679 | 683 | ||
684 | /* skip the skip_width */ | ||
680 | while (*str != '\0') | 685 | while (*str != '\0') |
681 | { | 686 | { |
682 | oldstr = str; | 687 | oldstr = str; |
@@ -688,6 +693,8 @@ static unsigned char *decode2utf8(const unsigned char *src, unsigned char *dst, | |||
688 | break; | 693 | break; |
689 | } | 694 | } |
690 | } | 695 | } |
696 | |||
697 | /* decode until string end or disp_width reached */ | ||
691 | width = 0; | 698 | width = 0; |
692 | while(*str != '\0') | 699 | while(*str != '\0') |
693 | { | 700 | { |
@@ -699,9 +706,11 @@ static unsigned char *decode2utf8(const unsigned char *src, unsigned char *dst, | |||
699 | utf8 = rb->utf8encode(ch, utf8); | 706 | utf8 = rb->utf8encode(ch, utf8); |
700 | } | 707 | } |
701 | 708 | ||
709 | /* return a pointer after the dst string ends */ | ||
702 | return utf8; | 710 | return utf8; |
703 | } | 711 | } |
704 | 712 | ||
713 | /* set max_columns and max_width */ | ||
705 | static void calc_max_width(void) | 714 | static void calc_max_width(void) |
706 | { | 715 | { |
707 | if (prefs.view_mode == NARROW) | 716 | if (prefs.view_mode == NARROW) |
@@ -1475,7 +1484,7 @@ static void viewer_draw(int col) | |||
1475 | #ifdef HAVE_LCD_BITMAP | 1484 | #ifdef HAVE_LCD_BITMAP |
1476 | /* show header */ | 1485 | /* show header */ |
1477 | viewer_show_header(); | 1486 | viewer_show_header(); |
1478 | 1487 | ||
1479 | /* show footer */ | 1488 | /* show footer */ |
1480 | viewer_show_footer(); | 1489 | viewer_show_footer(); |
1481 | #endif | 1490 | #endif |
@@ -2147,7 +2156,7 @@ static bool viewer_save_settings(void) | |||
2147 | viewer_add_bookmark(); | 2156 | viewer_add_bookmark(); |
2148 | bookmarks[bookmark_count-1].flag = BOOKMARK_LAST; | 2157 | bookmarks[bookmark_count-1].flag = BOOKMARK_LAST; |
2149 | } | 2158 | } |
2150 | 2159 | ||
2151 | tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC); | 2160 | tfd = rb->open(SETTINGS_TMP_FILE, O_WRONLY|O_CREAT|O_TRUNC); |
2152 | if (tfd < 0) | 2161 | if (tfd < 0) |
2153 | return false; | 2162 | return false; |
@@ -2637,7 +2646,7 @@ static bool alignment_setting(void) | |||
2637 | 2646 | ||
2638 | static bool autoscroll_speed_setting(void) | 2647 | static bool autoscroll_speed_setting(void) |
2639 | { | 2648 | { |
2640 | return rb->set_int("Auto-scroll Speed", "", UNIT_INT, | 2649 | return rb->set_int("Auto-scroll Speed", "", UNIT_INT, |
2641 | &prefs.autoscroll_speed, NULL, 1, 1, 10, NULL); | 2650 | &prefs.autoscroll_speed, NULL, 1, 1, 10, NULL); |
2642 | } | 2651 | } |
2643 | 2652 | ||
@@ -2869,8 +2878,7 @@ enum plugin_status plugin_start(const void* file) | |||
2869 | case VIEWER_SCREEN_LEFT | BUTTON_REPEAT: | 2878 | case VIEWER_SCREEN_LEFT | BUTTON_REPEAT: |
2870 | if (prefs.view_mode == WIDE) { | 2879 | if (prefs.view_mode == WIDE) { |
2871 | /* Screen left */ | 2880 | /* Screen left */ |
2872 | col -= draw_columns; | 2881 | col = col_limit(col - draw_columns); |
2873 | col = col_limit(col); | ||
2874 | } | 2882 | } |
2875 | else { /* prefs.view_mode == NARROW */ | 2883 | else { /* prefs.view_mode == NARROW */ |
2876 | /* Top of file */ | 2884 | /* Top of file */ |
@@ -2884,8 +2892,7 @@ enum plugin_status plugin_start(const void* file) | |||
2884 | case VIEWER_SCREEN_RIGHT | BUTTON_REPEAT: | 2892 | case VIEWER_SCREEN_RIGHT | BUTTON_REPEAT: |
2885 | if (prefs.view_mode == WIDE) { | 2893 | if (prefs.view_mode == WIDE) { |
2886 | /* Screen right */ | 2894 | /* Screen right */ |
2887 | col += draw_columns; | 2895 | col = col_limit(col + draw_columns); |
2888 | col = col_limit(col); | ||
2889 | } | 2896 | } |
2890 | else { /* prefs.view_mode == NARROW */ | 2897 | else { /* prefs.view_mode == NARROW */ |
2891 | /* Bottom of file */ | 2898 | /* Bottom of file */ |
@@ -2918,8 +2925,7 @@ enum plugin_status plugin_start(const void* file) | |||
2918 | case VIEWER_COLUMN_LEFT | BUTTON_REPEAT: | 2925 | case VIEWER_COLUMN_LEFT | BUTTON_REPEAT: |
2919 | if (prefs.view_mode == WIDE) { | 2926 | if (prefs.view_mode == WIDE) { |
2920 | /* Scroll left one column */ | 2927 | /* Scroll left one column */ |
2921 | col -= glyph_width('o'); | 2928 | col = col_limit(col - glyph_width('o')); |
2922 | col = col_limit(col); | ||
2923 | viewer_draw(col); | 2929 | viewer_draw(col); |
2924 | } | 2930 | } |
2925 | break; | 2931 | break; |
@@ -2928,8 +2934,7 @@ enum plugin_status plugin_start(const void* file) | |||
2928 | case VIEWER_COLUMN_RIGHT | BUTTON_REPEAT: | 2934 | case VIEWER_COLUMN_RIGHT | BUTTON_REPEAT: |
2929 | if (prefs.view_mode == WIDE) { | 2935 | if (prefs.view_mode == WIDE) { |
2930 | /* Scroll right one column */ | 2936 | /* Scroll right one column */ |
2931 | col += glyph_width('o'); | 2937 | col = col_limit(col + glyph_width('o')); |
2932 | col = col_limit(col); | ||
2933 | viewer_draw(col); | 2938 | viewer_draw(col); |
2934 | } | 2939 | } |
2935 | break; | 2940 | break; |