Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Oct 26th, 2011  |  syntax: None  |  size: 14.18 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff --git a/apps/filetree.c b/apps/filetree.c
  2. index 2407be9..d33b823 100644
  3. --- a/apps/filetree.c
  4. +++ b/apps/filetree.c
  5. @@ -424,13 +424,10 @@ static void ft_load_font(char *file)
  6.      set_file(file, (char *)global_settings.font_file, MAX_FILENAME);
  7.  #endif
  8.      splash(0, ID2P(LANG_WAIT));
  9. -    current_font_id = global_status.font_id[screen];
  10. +    current_font_id = screens[screen].getuifont();
  11.      if (current_font_id >= 0)
  12.          font_unload(current_font_id);
  13. -    current_font_id = font_load(file);
  14. -    if(screen==SCREEN_MAIN)
  15. -        font_set_ui(current_font_id);
  16. -    global_status.font_id[screen] = current_font_id;
  17. +    screens[screen].setuifont(font_load(file));
  18.      viewportmanager_theme_changed(THEME_UI_VIEWPORT);
  19.  }    
  20.  #endif
  21. diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
  22. index a9689a8..2dd4d44 100644
  23. --- a/apps/gui/skin_engine/skin_parser.c
  24. +++ b/apps/gui/skin_engine/skin_parser.c
  25. @@ -246,10 +246,12 @@ static int parse_statusbar_tags(struct skin_element* element,
  26.              viewport_set_fullscreen(&default_vp->vp, curr_screen);
  27.          }
  28.  #ifdef HAVE_REMOTE_LCD
  29. -        /* viewport_set_defaults() sets the font to FONT_UI+curr_screen.
  30. -         * This parser requires font 1 to always be the UI font,
  31. -         * so force it back to FONT_UI and handle the screen number at the end */
  32. -        default_vp->vp.font = FONT_UI;
  33. +        /* This parser requires viewports which will use the settings font to
  34. +         * have font == 1, but the above viewport_set() calls set font to
  35. +         * the current real font id. So force 1 here it will be set correctly
  36. +         * at the end
  37. +         */
  38. +        default_vp->vp.font = 1;
  39.  #endif
  40.      }
  41.      return 0;
  42. @@ -1645,7 +1647,7 @@ static bool skin_load_fonts(struct wps_data *data)
  43.          font_id = skin_vp->parsed_fontid;
  44.          if (font_id == 1)
  45.          {   /* the usual case -> built-in fonts */
  46. -            vp->font = global_status.font_id[curr_screen];
  47. +            vp->font = screens[curr_screen].getuifont();
  48.              continue;
  49.          }
  50.          else if (font_id <= 0)
  51. diff --git a/apps/gui/skin_engine/skin_render.c b/apps/gui/skin_engine/skin_render.c
  52. index 369bd46..4d41a6f 100644
  53. --- a/apps/gui/skin_engine/skin_render.c
  54. +++ b/apps/gui/skin_engine/skin_render.c
  55. @@ -658,7 +658,7 @@ void skin_render_viewport(struct skin_element* viewport, struct gui_wps *gwps,
  56.  
  57.      /* fix font ID's */
  58.      if (skin_viewport->parsed_fontid == 1)
  59. -        skin_viewport->vp.font = global_status.font_id[display->screen_type];
  60. +        skin_viewport->vp.font = display->getuifont();
  61.  #endif
  62.      
  63.      while (line)
  64. diff --git a/apps/gui/statusbar-skinned.c b/apps/gui/statusbar-skinned.c
  65. index 7850e7c..f79672c 100644
  66. --- a/apps/gui/statusbar-skinned.c
  67. +++ b/apps/gui/statusbar-skinned.c
  68. @@ -128,7 +128,7 @@ struct viewport *sb_skin_get_info_vp(enum screen_type screen)
  69.      if (!vp)
  70.          return NULL;
  71.      if (vp->parsed_fontid == 1)
  72. -        vp->vp.font = global_status.font_id[screen];
  73. +        vp->vp.font = screens[screen].getuifont();
  74.      return &vp->vp;
  75.  }
  76.  
  77. diff --git a/apps/gui/usb_screen.c b/apps/gui/usb_screen.c
  78. index 06770b1..2b7d472 100644
  79. --- a/apps/gui/usb_screen.c
  80. +++ b/apps/gui/usb_screen.c
  81. @@ -265,8 +265,8 @@ void gui_usb_screen_run(bool early_usb)
  82.  #ifdef HAVE_LCD_BITMAP
  83.          FOR_NB_SCREENS(i)
  84.          {
  85. -            font_unload(global_status.font_id[i]);
  86. -            global_status.font_id[i] = -1;
  87. +            font_unload(screens[i].getuifont());
  88. +            screens[i].setuifont(FONT_SYSFIXED);
  89.          }
  90.          skin_unload_all();
  91.  #endif
  92. diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c
  93. index c5e4427..b17f765 100644
  94. --- a/apps/gui/viewport.c
  95. +++ b/apps/gui/viewport.c
  96. @@ -317,7 +317,7 @@ void viewport_set_fullscreen(struct viewport *vp,
  97.  #ifndef __PCTOOL__
  98.      set_default_align_flags(vp);
  99.  #endif
  100. -    vp->font = global_status.font_id[screen];
  101. +    vp->font = screens[screen].getuifont();
  102.      vp->line_height = font_get(vp->font)->height;
  103.      vp->drawmode = DRMODE_SOLID;
  104.  #if LCD_DEPTH > 1
  105. diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c
  106. index d9f76f7..1c4bbca 100644
  107. --- a/apps/plugins/bubbles.c
  108. +++ b/apps/plugins/bubbles.c
  109. @@ -1435,7 +1435,7 @@ static void bubbles_drawboard(struct game_context* bb) {
  110.  
  111.      /* clear screen */
  112.      rb->lcd_clear_display();
  113. -    int font = rb->screens[SCREEN_MAIN]->getfont();
  114. +    int font = rb->screens[SCREEN_MAIN]->getuifont();
  115.      h = rb->font_get(font)->height + 1;
  116.      /* draw background */
  117.  #ifdef HAVE_LCD_COLOR
  118. diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c
  119. index c4cfe48..4910c74 100644
  120. --- a/apps/recorder/keyboard.c
  121. +++ b/apps/recorder/keyboard.c
  122. @@ -720,7 +720,7 @@ static void kbd_calc_params(struct keyboard_parameters *pm,
  123.                                  (touchscreen_get_mode() == TOUCHSCREEN_POINT));
  124.  #endif
  125.  
  126. -    pm->curfont = pm->default_lines ? FONT_SYSFIXED : FONT_UI;
  127. +    pm->curfont = pm->default_lines ? FONT_SYSFIXED : sc->getuifont();
  128.      font = font_get(pm->curfont);
  129.      pm->font_h = font->height;
  130.  
  131. diff --git a/apps/screen_access.c b/apps/screen_access.c
  132. index 01fdebe..ac0f31d 100644
  133. --- a/apps/screen_access.c
  134. +++ b/apps/screen_access.c
  135. @@ -77,6 +77,22 @@ void screen_helper_setfont(int font)
  136.  #endif
  137.  }
  138.  
  139. +int screen_helper_getuifont(void)
  140. +{
  141. +#ifdef HAVE_LCD_BITMAP
  142. +    return global_status.font_id[SCREEN_MAIN];
  143. +#else
  144. +    return FONT_SYSFIXED;
  145. +#endif
  146. +}
  147. +
  148. +void screen_helper_setuifont(int font)
  149. +{
  150. +#ifdef HAVE_LCD_BITMAP
  151. +    global_status.font_id[SCREEN_MAIN] = font;
  152. +#endif
  153. +}
  154. +
  155.  #if NB_SCREENS == 2
  156.  static int screen_helper_remote_getcharwidth(void)
  157.  {
  158. @@ -116,6 +132,23 @@ void screen_helper_remote_setfont(int font)
  159.          font = global_status.font_id[SCREEN_REMOTE];
  160.      lcd_remote_setfont(font);
  161.  }
  162. +
  163. +int screen_helper_remote_getuifont(void)
  164. +{
  165. +#ifdef HAVE_LCD_BITMAP
  166. +    return global_status.font_id[SCREEN_REMOTE];
  167. +#else
  168. +    return FONT_SYSFIXED;
  169. +#endif
  170. +}
  171. +
  172. +void screen_helper_remote_setuifont(int font)
  173. +{
  174. +#ifdef HAVE_LCD_BITMAP
  175. +    global_status.font_id[SCREEN_REMOTE] = font;
  176. +#endif
  177. +}
  178. +
  179.  #endif
  180.  
  181.  struct screen screens[NB_SCREENS] =
  182. @@ -147,7 +180,8 @@ struct screen screens[NB_SCREENS] =
  183.          .getstringsize=&lcd_getstringsize,
  184.  #ifdef HAVE_LCD_BITMAP
  185.          .setfont=screen_helper_setfont,
  186. -        .getfont=&lcd_getfont,
  187. +        .getuifont=screen_helper_getuifont,
  188. +        .setuifont=screen_helper_setuifont,
  189.          .mono_bitmap=&lcd_mono_bitmap,
  190.          .mono_bitmap_part=&lcd_mono_bitmap_part,
  191.          .set_drawmode=&lcd_set_drawmode,
  192. @@ -246,8 +280,9 @@ struct screen screens[NB_SCREENS] =
  193.          .getheight=&lcd_remote_getheight,
  194.          .getstringsize=&lcd_remote_getstringsize,
  195.  #if 1 /* all remote LCDs are bitmapped so far */
  196. -        .setfont=screen_helper_setfont,
  197. -        .getfont=&lcd_remote_getfont,
  198. +        .setfont=screen_helper_remote_setfont,
  199. +        .getuifont=screen_helper_remote_getuifont,
  200. +        .setuifont=screen_helper_remote_setuifont,
  201.          .mono_bitmap=&lcd_remote_mono_bitmap,
  202.          .mono_bitmap_part=&lcd_remote_mono_bitmap_part,
  203.          .bitmap=(screen_bitmap_func*)&lcd_remote_bitmap,
  204. diff --git a/apps/screen_access.h b/apps/screen_access.h
  205. index 2713219..04cc6f4 100644
  206. --- a/apps/screen_access.h
  207. +++ b/apps/screen_access.h
  208. @@ -71,7 +71,8 @@ struct screen
  209.      int (*getstringsize)(const unsigned char *str, int *w, int *h);
  210.  #if defined(HAVE_LCD_BITMAP) || defined(HAVE_REMOTE_LCD) /* always bitmap */
  211.      void (*setfont)(int newfont);
  212. -    int (*getfont)(void);
  213. +    int (*getuifont)(void);
  214. +    void (*setuifont)(int newfont);
  215.  
  216.      void (*scroll_step)(int pixels);
  217.      void (*puts_style_offset)(int x, int y, const unsigned char *str,
  218. diff --git a/apps/settings.c b/apps/settings.c
  219. index 7142cfb..fbfa438 100644
  220. --- a/apps/settings.c
  221. +++ b/apps/settings.c
  222. @@ -876,37 +876,38 @@ void settings_apply(bool read_disk)
  223.          /* fonts need to be loaded before the WPS */
  224.          if (global_settings.font_file[0]
  225.              && global_settings.font_file[0] != '-') {
  226. -            const char* loaded_font = font_filename(global_status.font_id[SCREEN_MAIN]);
  227. +            int font_ui = screens[SCREEN_MAIN].getuifont();
  228. +            const char* loaded_font = font_filename(font_ui);
  229.              
  230.              snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
  231.                       global_settings.font_file);
  232.              if (!loaded_font || strcmp(loaded_font, buf))
  233.              {
  234.                  CHART2(">font_load ", global_settings.font_file);
  235. -                if (global_status.font_id[SCREEN_MAIN] >= 0)
  236. -                    font_unload(global_status.font_id[SCREEN_MAIN]);
  237. +                if (font_ui >= 0)
  238. +                    font_unload(font_ui);
  239.                  rc = font_load(buf);
  240. -                font_set_ui(rc);
  241.                  CHART2("<font_load ", global_settings.font_file);
  242. -                global_status.font_id[SCREEN_MAIN] = rc;
  243. -                lcd_setfont(rc);
  244. +                screens[SCREEN_MAIN].setuifont(rc);
  245. +                screens[SCREEN_MAIN].setfont(rc);
  246.              }
  247.          }
  248.  #ifdef HAVE_REMOTE_LCD        
  249.          if ( global_settings.remote_font_file[0]
  250.              && global_settings.remote_font_file[0] != '-') {
  251. -            const char* loaded_font = font_filename(global_status.font_id[SCREEN_REMOTE]);
  252. +            int font_ui = screens[SCREEN_REMOTE].getuifont();
  253. +            const char* loaded_font = font_filename(font_ui);
  254.              snprintf(buf, sizeof buf, FONT_DIR "/%s.fnt",
  255.                       global_settings.remote_font_file);
  256.              if (!loaded_font || strcmp(loaded_font, buf))
  257.              {
  258.                  CHART2(">font_load_remoteui ", global_settings.remote_font_file);
  259. -                if (global_status.font_id[SCREEN_REMOTE] >= 0)
  260. -                    font_unload(global_status.font_id[SCREEN_REMOTE]);
  261. +                if (font_ui >= 0)
  262. +                    font_unload(font_ui);
  263.                  rc = font_load(buf);
  264.                  CHART2("<font_load_remoteui ", global_settings.remote_font_file);
  265. -                global_status.font_id[SCREEN_REMOTE] = rc;
  266. -                lcd_remote_setfont(rc);
  267. +                screens[SCREEN_REMOTE].setuifont(rc);
  268. +                screens[SCREEN_REMOTE].setfont(rc);
  269.              }
  270.          }
  271.  #endif
  272. @@ -1076,10 +1077,11 @@ void settings_reset(void)
  273.  #ifdef HAVE_LCD_BITMAP
  274.      FOR_NB_SCREENS(i)
  275.      {
  276. -        if (global_status.font_id[i] > FONT_SYSFIXED)
  277. +        if (screens[i].getuifont() > FONT_SYSFIXED)
  278.          {
  279. -            font_unload(global_status.font_id[i]);
  280. -            global_status.font_id[i] = FONT_SYSFIXED;
  281. +            font_unload(screens[i].getuifont());
  282. +            screens[i].setuifont(FONT_SYSFIXED);
  283. +            screens[i].setfont(FONT_SYSFIXED);
  284.          }
  285.      }
  286.  #endif
  287. diff --git a/firmware/export/font.h b/firmware/export/font.h
  288. index 76f86c8..914d3aa 100644
  289. --- a/firmware/export/font.h
  290. +++ b/firmware/export/font.h
  291. @@ -55,7 +55,7 @@ enum {
  292.  
  293.  /* SYSFONT, FONT_UI, FONT_UI_REMOTE + MAXUSERFONTS fonts in skins */
  294.  #define MAXFONTS (FONT_FIRSTUSERFONT + MAXUSERFONTS)
  295. -#define FONT_UI MAXUSERFONTS
  296. +#define FONT_UI MAXFONTS
  297.  
  298.  /*
  299.   * .fnt loadable font file format definition
  300. @@ -124,9 +124,6 @@ int font_glyphs_to_bufsize(const char *path, int glyphs);
  301.  void font_unload(int font_id);
  302.  void font_unload_all(void);
  303.  void font_lock(int font_id, bool lock);
  304. -/* set the default UI font */
  305. -void font_set_ui(int font_id);
  306. -int  font_get_ui(void);
  307.  
  308.  struct font* font_get(int font);
  309.  
  310. diff --git a/firmware/font.c b/firmware/font.c
  311. index eb15bb7..f1cddb0 100644
  312. --- a/firmware/font.c
  313. +++ b/firmware/font.c
  314. @@ -88,7 +88,6 @@ struct buflib_alloc_data {
  315.  };
  316.  static int buflib_allocations[MAXFONTS];
  317.  
  318. -static int font_ui = -1;
  319.  static int cache_fd;
  320.  static struct font* cache_pf;
  321.  
  322. @@ -560,7 +559,7 @@ int font_load_ex(const char *path, size_t buffer_size)
  323.          
  324.      lock_font_handle(handle, false);
  325.      buflib_allocations[font_id] = handle;
  326. -    //printf("%s -> [%d] -> %d\n", path, font_id, handle);
  327. +    //printf("%s -> [%d] -> %d\n", path, font_id, *handle);
  328.      return font_id; /* success!*/
  329.  }
  330.  int font_load(const char *path)
  331. @@ -617,52 +616,28 @@ void font_unload_all(void)
  332.  
  333.  /*
  334.   * Return a pointer to an incore font structure.
  335. - * Return the requested font, font_ui, or sysfont
  336. + * If the requested font isn't loaded/compiled-in,
  337. + * decrement the font number and try again.
  338.   */
  339. -struct font* font_get(int font_id)
  340. +struct font* font_get(int font)
  341.  {
  342. -    struct buflib_alloc_data *alloc;
  343. -    struct font *pf;
  344. -    int handle, id=-1;
  345. -
  346. -    if( font_id == FONT_UI )
  347. -        id = font_ui;
  348. -
  349. -    if( font_id == FONT_SYSFIXED )
  350. +    struct font* pf;
  351. +    if (font == FONT_UI)
  352. +        font = MAXFONTS-1;
  353. +    if (font <= FONT_SYSFIXED)
  354.          return &sysfont;
  355. -    
  356. -    if( id == -1 )
  357. -        id = font_id;
  358. -    
  359. -    handle = buflib_allocations[id];
  360. -    if( handle > 0 )
  361. -    {
  362. -        alloc =  core_get_data(buflib_allocations[id]);
  363. -        pf=&alloc->font;
  364. -        if( pf && pf->height )
  365. -            return pf;
  366. -    }
  367. -    handle = buflib_allocations[font_ui];
  368. -    if( handle > 0 )
  369. -    {
  370. -        alloc = core_get_data(buflib_allocations[font_ui]);
  371. -        pf=&alloc->font;
  372. -        if( pf && pf->height )
  373. -            return pf;
  374. -    }
  375. -
  376. -    return &sysfont;
  377. -}
  378. -
  379. -void font_set_ui( int font_id )
  380. -{
  381. -    font_ui = font_id;
  382. -    return;
  383. -}
  384.  
  385. -int font_get_ui()
  386. -{
  387. -    return font_ui;
  388. +    while (1) {
  389. +        if (buflib_allocations[font] > 0)
  390. +        {
  391. +            struct buflib_alloc_data *alloc = core_get_data(buflib_allocations[font]);
  392. +            pf = &alloc->font;
  393. +            if (pf && pf->height)
  394. +                return pf;
  395. +        }
  396. +        if (--font < 0)
  397. +            return &sysfont;
  398. +    }
  399.  }
  400.  
  401.  static int pf_to_handle(struct font* pf)
  402. @@ -1005,18 +980,6 @@ struct font* font_get(int font)
  403.      return &sysfont;
  404.  }
  405.  
  406. -void font_set_ui(int font_id)
  407. -{
  408. -    (void)font_id;
  409. -    return;
  410. -}
  411. -
  412. -int font_get_ui()
  413. -{
  414. -    return FONT_SYSFIXED;
  415. -}
  416. -
  417. -
  418.  /*
  419.   * Returns width of character
  420.   */
  421.  
  422.