2018-04-30 18:21:34 -05:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
#include "common/String.h"
|
|
|
|
#include "font.h"
|
|
|
|
|
|
|
|
class FontReader
|
|
|
|
{
|
|
|
|
unsigned char *pointer;
|
|
|
|
int width;
|
|
|
|
int pixels;
|
|
|
|
int data;
|
|
|
|
|
|
|
|
inline FontReader(unsigned char *_pointer):
|
|
|
|
pointer(_pointer + 1),
|
|
|
|
width(*_pointer),
|
|
|
|
pixels(0),
|
|
|
|
data(0)
|
|
|
|
{}
|
|
|
|
|
2018-04-30 21:57:03 -05:00
|
|
|
static inline unsigned char *lookupChar(String::value_type ch)
|
|
|
|
{
|
|
|
|
size_t offset = 0;
|
|
|
|
for(int i = 0; font_ranges[i][1]; i++)
|
|
|
|
if(font_ranges[i][0] > ch)
|
|
|
|
break;
|
|
|
|
else if(font_ranges[i][1] >= ch)
|
|
|
|
return &font_data[font_ptrs[offset + (ch - font_ranges[i][0])]];
|
|
|
|
else
|
|
|
|
offset += font_ranges[i][1] - font_ranges[i][0] + 1;
|
|
|
|
if(ch == 0xFFFD)
|
|
|
|
return &font_data[0];
|
|
|
|
else
|
|
|
|
return lookupChar(0xFFFD);
|
|
|
|
}
|
|
|
|
|
2018-04-30 18:21:34 -05:00
|
|
|
public:
|
|
|
|
inline FontReader(String::value_type ch):
|
2018-04-30 21:57:03 -05:00
|
|
|
FontReader(lookupChar(ch))
|
2018-04-30 18:21:34 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int GetWidth() const
|
|
|
|
{
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int NextPixel()
|
|
|
|
{
|
|
|
|
if(!pixels)
|
|
|
|
{
|
|
|
|
data = *(pointer++);
|
|
|
|
pixels = 4;
|
|
|
|
}
|
|
|
|
int old = data;
|
|
|
|
pixels--;
|
|
|
|
data >>= 2;
|
|
|
|
return old & 0x3;
|
|
|
|
}
|
|
|
|
};
|