00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "bitmap_font.hpp"
00025 #include "generic_bitmap.hpp"
00026 #include "../utils/ustring.hpp"
00027
00028
00029 BitmapFont::BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
00030 const string &rType ):
00031 GenericFont( pIntf ), m_rBitmap( rBitmap )
00032 {
00033 int i;
00034
00035
00036 if( rType == "digits" )
00037 {
00038 m_width = 9;
00039 m_height = 13;
00040 m_advance = 12;
00041 m_skip = 6;
00042 for( i = 0; i <= 9; i++ )
00043 {
00044 m_table['0'+i].m_xPos = i * m_width;
00045 }
00046 m_table[(size_t)'-'].m_xPos = 11 * m_width;
00047 }
00048 else if( rType == "text" )
00049 {
00050 m_width = 5;
00051 m_height = 6;
00052 m_advance = 5;
00053 m_skip = 5;
00054 for( i = 0; i < 26; i++ )
00055 {
00056 m_table['A'+i].m_xPos = m_table['a'+i].m_xPos = i * m_width;
00057 }
00058 m_table[(size_t)'"'].m_xPos = 26 * m_width;
00059 m_table[(size_t)'@'].m_xPos = 27 * m_width;
00060 m_table[(size_t)' '].m_xPos = 29 * m_width;
00061 for( i = 0; i <= 9; i++ )
00062 {
00063 m_table['0'+i].m_xPos = i * m_width;
00064 m_table['0'+i].m_yPos = m_height;
00065 }
00066 static const char specialChars[] = {'.', ':', '(', ')', '-', '\'',
00067 '!', '_', '+', '\\', '/', '[', ']', '^', '&', '%', ',', '=', '$',
00068 '#'};
00069 for( i = 0; i < 19; i++ )
00070 {
00071 m_table[(size_t)specialChars[i]].m_xPos = (11 + i) * m_width;
00072 m_table[(size_t)specialChars[i]].m_yPos = m_height;
00073 }
00074 m_table[(size_t)'?'].m_xPos = 4 * m_width;
00075 m_table[(size_t)'*'].m_xPos = 5 * m_width;
00076 m_table[(size_t)'?'].m_yPos = m_table[(size_t)'*'].m_yPos = 2 * m_height;
00077 }
00078 }
00079
00080
00081 GenericBitmap *BitmapFont::drawString( const UString &rString,
00082 uint32_t color, int maxWidth ) const
00083 {
00084 uint32_t *pString = (uint32_t*)rString.u_str();
00085
00086 int width = 0;
00087 for( uint32_t *ptr = pString; *ptr; ptr++ )
00088 {
00089 uint32_t c = *ptr;
00090 if( c < 256 && m_table[c].m_xPos != -1 )
00091 {
00092 width += m_advance;
00093 }
00094 else
00095 {
00096 width += m_skip;
00097 }
00098 }
00099
00100 BitmapImpl *pBmp = new BitmapImpl( getIntf(), width, m_height );
00101 int xDest = 0;
00102 while( *pString )
00103 {
00104 uint32_t c = *(pString++);
00105 if( c < 256 && m_table[c].m_xPos != -1 )
00106 {
00107 pBmp->drawBitmap( m_rBitmap, m_table[c].m_xPos, m_table[c].m_yPos,
00108 xDest, 0, m_width, m_height );
00109 xDest += m_advance;
00110 }
00111 else
00112 {
00113 xDest += m_skip;
00114 }
00115 }
00116 return pBmp;
00117 }
00118