diff options
author | Tomer Shalev <shalev.tomer@gmail.com> | 2010-04-07 18:06:47 +0000 |
---|---|---|
committer | Tomer Shalev <shalev.tomer@gmail.com> | 2010-04-07 18:06:47 +0000 |
commit | 8b2ec40a5516d84d7e10869d7238e884a13749e2 (patch) | |
tree | 36222f4a69829a9785f1cdfb33e55fb0bb0ddac4 /apps | |
parent | 2434a92b609a894b7abba23dcdd63756bdfd682f (diff) | |
download | rockbox-8b2ec40a5516d84d7e10869d7238e884a13749e2.tar.gz rockbox-8b2ec40a5516d84d7e10869d7238e884a13749e2.zip |
FS#11185 - Text viewer returns div by 0 if font is missing, renamed or corrupted
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25517 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/viewer.c | 45 |
1 files changed, 35 insertions, 10 deletions
diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c index a5d51591ae..390782ca6d 100644 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c | |||
@@ -1683,7 +1683,7 @@ static void init_header_and_footer(void) | |||
1683 | last_screen_top_ptr = NULL; | 1683 | last_screen_top_ptr = NULL; |
1684 | } | 1684 | } |
1685 | 1685 | ||
1686 | static void change_font(unsigned char *font) | 1686 | static bool change_font(unsigned char *font) |
1687 | { | 1687 | { |
1688 | unsigned char buf[MAX_PATH]; | 1688 | unsigned char buf[MAX_PATH]; |
1689 | 1689 | ||
@@ -1691,8 +1691,19 @@ static void change_font(unsigned char *font) | |||
1691 | return; | 1691 | return; |
1692 | 1692 | ||
1693 | rb->snprintf(buf, MAX_PATH, "%s/%s.fnt", FONT_DIR, font); | 1693 | rb->snprintf(buf, MAX_PATH, "%s/%s.fnt", FONT_DIR, font); |
1694 | if (rb->font_load(NULL, buf) < 0) | 1694 | if (rb->font_load(NULL, buf) < 0) { |
1695 | rb->splash(HZ/2, "font load failed."); | 1695 | rb->splash(HZ/2, "Font load failed."); |
1696 | |||
1697 | return false; | ||
1698 | } | ||
1699 | |||
1700 | return true; | ||
1701 | } | ||
1702 | |||
1703 | static void revert_font() | ||
1704 | { | ||
1705 | if (rb->strcmp(prefs.font, rb->global_settings->font_file)) | ||
1706 | change_font(rb->global_settings->font_file); | ||
1696 | } | 1707 | } |
1697 | #endif | 1708 | #endif |
1698 | 1709 | ||
@@ -1701,6 +1712,9 @@ static bool viewer_init(void) | |||
1701 | #ifdef HAVE_LCD_BITMAP | 1712 | #ifdef HAVE_LCD_BITMAP |
1702 | /* initialize fonts */ | 1713 | /* initialize fonts */ |
1703 | pf = rb->font_get(FONT_UI); | 1714 | pf = rb->font_get(FONT_UI); |
1715 | if (pf == NULL) | ||
1716 | return false; | ||
1717 | |||
1704 | draw_columns = display_columns = LCD_WIDTH; | 1718 | draw_columns = display_columns = LCD_WIDTH; |
1705 | #else | 1719 | #else |
1706 | /* REAL fixed pitch :) all chars use up 1 cell */ | 1720 | /* REAL fixed pitch :) all chars use up 1 cell */ |
@@ -2079,7 +2093,7 @@ static bool viewer_save_global_settings(void) | |||
2079 | return true; | 2093 | return true; |
2080 | } | 2094 | } |
2081 | 2095 | ||
2082 | static void viewer_load_settings(void) | 2096 | static bool viewer_load_settings(void) |
2083 | { | 2097 | { |
2084 | unsigned char buf[MAX_PATH+2]; | 2098 | unsigned char buf[MAX_PATH+2]; |
2085 | unsigned int fcount; | 2099 | unsigned int fcount; |
@@ -2176,12 +2190,18 @@ read_end: | |||
2176 | start_position = file_pos + screen_top_ptr - buffer; | 2190 | start_position = file_pos + screen_top_ptr - buffer; |
2177 | 2191 | ||
2178 | #ifdef HAVE_LCD_BITMAP | 2192 | #ifdef HAVE_LCD_BITMAP |
2179 | if (rb->strcmp(prefs.font, rb->global_settings->font_file)) | 2193 | if (rb->strcmp(prefs.font, rb->global_settings->font_file)) { |
2180 | change_font(prefs.font); | 2194 | if (!change_font(prefs.font)) { |
2195 | revert_font(); | ||
2196 | return false; | ||
2197 | } | ||
2198 | } | ||
2181 | 2199 | ||
2182 | init_need_scrollbar(); | 2200 | init_need_scrollbar(); |
2183 | init_header_and_footer(); | 2201 | init_header_and_footer(); |
2184 | #endif | 2202 | #endif |
2203 | |||
2204 | return true; | ||
2185 | } | 2205 | } |
2186 | 2206 | ||
2187 | static bool copy_bookmark_file(int sfd, int dfd, off_t start, off_t size) | 2207 | static bool copy_bookmark_file(int sfd, int dfd, off_t start, off_t size) |
@@ -2627,7 +2647,7 @@ static bool font_setting(void) | |||
2627 | dir = rb->opendir(FONT_DIR); | 2647 | dir = rb->opendir(FONT_DIR); |
2628 | if (!dir) | 2648 | if (!dir) |
2629 | { | 2649 | { |
2630 | rb->splash(HZ/2, "font dir does not access."); | 2650 | rb->splash(HZ/2, "Font dir is not accessible"); |
2631 | return false; | 2651 | return false; |
2632 | } | 2652 | } |
2633 | 2653 | ||
@@ -2653,7 +2673,7 @@ static bool font_setting(void) | |||
2653 | dir = rb->opendir(FONT_DIR); | 2673 | dir = rb->opendir(FONT_DIR); |
2654 | if (!dir) | 2674 | if (!dir) |
2655 | { | 2675 | { |
2656 | rb->splash(HZ/2, "font dir does not access."); | 2676 | rb->splash(HZ/2, "Font dir is not accessible"); |
2657 | return false; | 2677 | return false; |
2658 | } | 2678 | } |
2659 | 2679 | ||
@@ -2695,9 +2715,13 @@ static bool font_setting(void) | |||
2695 | 2715 | ||
2696 | if (new_font != old_font) | 2716 | if (new_font != old_font) |
2697 | { | 2717 | { |
2718 | if (!change_font(prefs.font)) | ||
2719 | { | ||
2720 | revert_font(); | ||
2721 | return false; | ||
2722 | } | ||
2698 | rb->memset(prefs.font, 0, MAX_PATH); | 2723 | rb->memset(prefs.font, 0, MAX_PATH); |
2699 | rb->snprintf(prefs.font, MAX_PATH, "%s", names[new_font].string); | 2724 | rb->snprintf(prefs.font, MAX_PATH, "%s", names[new_font].string); |
2700 | change_font(prefs.font); | ||
2701 | } | 2725 | } |
2702 | 2726 | ||
2703 | return res; | 2727 | return res; |
@@ -2852,7 +2876,8 @@ enum plugin_status plugin_start(const void* file) | |||
2852 | return PLUGIN_ERROR; | 2876 | return PLUGIN_ERROR; |
2853 | } | 2877 | } |
2854 | 2878 | ||
2855 | viewer_load_settings(); /* load the preferences and bookmark */ | 2879 | if (!viewer_load_settings()) /* load the preferences and bookmark */ |
2880 | return PLUGIN_ERROR; | ||
2856 | 2881 | ||
2857 | #if LCD_DEPTH > 1 | 2882 | #if LCD_DEPTH > 1 |
2858 | rb->lcd_set_backdrop(NULL); | 2883 | rb->lcd_set_backdrop(NULL); |