Terminal: fixed: font sizes now work
[webos-internals:applications.git] / termplugin / fontinfo.cpp
1 #include "fontinfo.hpp"
2 #include "common.h"
3 #include <stdio.h>
4 #include "font.xpm"
5 #include "font-4x6.xpm"
6 #include "font-5x7.xpm"
7 #include "font-6x10.xpm"
8
9
10 typedef struct
11         {
12         int width;
13         int height;
14         const char **data;
15         }FontFiles;
16 static const FontFiles fontFiles[] =
17         {
18                 {       width:4,        height:6,       data:font_4x6_xpm       },
19                 {       width:5,        height:7,       data:font_5x7_xpm       },
20                 {       width:8,        height:8,       data:font_8x8_xpm       },
21                 {       width:6,        height:10,      data:font_6x10_xpm      },
22                 {       0, 0, 0 },
23         };
24
25 FontInfo::FontInfo(int width,int height) :
26         _glyph_start(32),
27         _glyph_end(127)
28         {
29         const FontFiles *ff = fontFiles;
30         for(; ff->height; ff++)
31                 {
32                 if(ff->height >= height)
33                         break;
34                 }
35         if(!ff->height)
36                 ff--;   //      use largest font
37         _char_width = ff->width;
38         _char_height = ff->height;
39         _glyph_data = ff->data;
40 #if 0
41         if(height >= 8)
42         {
43                 _char_width = 8;
44                 _char_height = 8;
45                 _glyph_data = font_8x8_xpm;
46         }
47         else
48         {
49                 _char_width = 4;
50                 _char_height = 6;
51                 _glyph_data = font_4x6_xpm;
52         }
53 #endif
54         my_fprintf(stderr,"  FontInfo(width:%d, height:%d): width:%d, height:%d\n", width, height, _char_width, _char_height);
55         }
56
57 int FontInfo::getLine(int y)
58 {
59         return (y + _char_height - 1) / _char_height;
60 }