summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/plugins/viewer.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c
index fbc70fc9ff..80b279c638 100644
--- a/apps/plugins/viewer.c
+++ b/apps/plugins/viewer.c
@@ -728,9 +728,17 @@ static void calc_max_width(void)
728static bool done = false; 728static bool done = false;
729static int col = 0; 729static int col = 0;
730 730
731#define ADVANCE_COUNTERS(c) { width += glyph_width(c); k++; } 731static inline void advance_conters(unsigned short ch, int* k, int* width)
732#define LINE_IS_FULL ((k>=max_columns-1) ||( width >= max_width)) 732{
733#define LINE_IS_NOT_FULL ((k<max_columns-1) &&( width < max_width)) 733 *width += glyph_width(ch);
734 (*k)++;
735}
736
737static inline bool line_is_full(int k, int width)
738{
739 return ((k >= max_columns - 1) || (width >= max_width));
740}
741
734static unsigned char* crop_at_width(const unsigned char* p) 742static unsigned char* crop_at_width(const unsigned char* p)
735{ 743{
736 int k,width; 744 int k,width;
@@ -739,12 +747,12 @@ static unsigned char* crop_at_width(const unsigned char* p)
739 747
740 k=width=0; 748 k=width=0;
741 749
742 while (LINE_IS_NOT_FULL) { 750 while (!line_is_full(k, width)) {
743 oldp = p; 751 oldp = p;
744 if (BUFFER_OOB(p)) 752 if (BUFFER_OOB(p))
745 break; 753 break;
746 p = get_ucs(p, &ch); 754 p = get_ucs(p, &ch);
747 ADVANCE_COUNTERS(ch); 755 advance_conters(ch, &k, &width);
748 } 756 }
749 757
750 return (unsigned char*)oldp; 758 return (unsigned char*)oldp;
@@ -824,7 +832,7 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
824 for (j=k=width=spaces=newlines=0; ; j++) { 832 for (j=k=width=spaces=newlines=0; ; j++) {
825 if (BUFFER_OOB(cur_line+j)) 833 if (BUFFER_OOB(cur_line+j))
826 return NULL; 834 return NULL;
827 if (LINE_IS_FULL) { 835 if (line_is_full(k, width)) {
828 size = search_len = j; 836 size = search_len = j;
829 break; 837 break;
830 } 838 }
@@ -840,7 +848,7 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
840 } 848 }
841 if (j==0) /* i=1 is intentional */ 849 if (j==0) /* i=1 is intentional */
842 for (i=0; i<par_indent_spaces; i++) 850 for (i=0; i<par_indent_spaces; i++)
843 ADVANCE_COUNTERS(' '); 851 advance_conters(' ', &k, &width);
844 } 852 }
845 if (!first_chars) spaces++; 853 if (!first_chars) spaces++;
846 break; 854 break;
@@ -866,8 +874,8 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
866 if (prefs.line_mode==JOIN || newlines>0) { 874 if (prefs.line_mode==JOIN || newlines>0) {
867 while (spaces) { 875 while (spaces) {
868 spaces--; 876 spaces--;
869 ADVANCE_COUNTERS(' '); 877 advance_conters(' ', &k, &width);
870 if (LINE_IS_FULL) { 878 if (line_is_full(k, width)) {
871 size = search_len = j; 879 size = search_len = j;
872 break; 880 break;
873 } 881 }
@@ -879,14 +887,14 @@ static unsigned char* find_next_line(const unsigned char* cur_line, bool *is_sho
879 * while drawing. */ 887 * while drawing. */
880 search_len = size; 888 search_len = size;
881 spaces=0; 889 spaces=0;
882 ADVANCE_COUNTERS(' '); 890 advance_conters(' ', &k, &width);
883 if (LINE_IS_FULL) { 891 if (line_is_full(k, width)) {
884 size = search_len = j; 892 size = search_len = j;
885 break; 893 break;
886 } 894 }
887 } 895 }
888 first_chars = false; 896 first_chars = false;
889 ADVANCE_COUNTERS(c); 897 advance_conters(ch, &k, &width);
890 break; 898 break;
891 } 899 }
892 } 900 }