Commit ab603b47 authored by Cyril Deguet's avatar Cyril Deguet

* all: beginning of "text" bitmap font support. The text bitmap must have

  the following layout: [cf xmms skins ;)]
parent 00aa16f1
......@@ -144,7 +144,7 @@ void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
GenericBitmap *pBmp = new PngBitmap( getIntf(), rData.m_file, 0 );
m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp );
GenericFont *pFont = new BitmapFont( getIntf(), *pBmp );
GenericFont *pFont = new BitmapFont( getIntf(), *pBmp, rData.m_type );
if( pFont->init() )
{
m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
......
......@@ -26,11 +26,39 @@
#include "../utils/ustring.hpp"
BitmapFont::BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap ):
BitmapFont::BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
const string &rType ):
GenericFont( pIntf ), m_rBitmap( rBitmap )
{
if( rType == "digits" )
{
m_width = 9;
m_height = 13;
m_advance = 12;
m_skip = 6;
for( int i = 0; i <= 9; i++ )
{
m_table['0'+i].m_xPos = i * m_width;
}
m_table[(size_t)'-'].m_xPos = 11 * m_width;
}
else if( rType == "text" )
{
m_width = 5;
m_height = 6;
m_advance = 5;
m_skip = 5;
for( int i = 0; i < 26; i++ )
{
m_table['A'+i].m_xPos = i * m_width;
m_table['a'+i].m_xPos = i * m_width;
}
for( int i = 0; i <= 9; i++ )
{
m_table['0'+i].m_xPos = i * m_width;
m_table['0'+i].m_yPos = m_height;
}
}
}
......@@ -43,13 +71,13 @@ GenericBitmap *BitmapFont::drawString( const UString &rString,
for( uint32_t *ptr = pString; *ptr; ptr++ )
{
uint32_t c = *ptr;
if( (c >= '0' && c <= '9') || c == '-' )
if( c < 256 && m_table[c].m_xPos != -1 )
{
width += m_width + 3;
width += m_advance;
}
else
{
width += 6;
width += m_skip;
}
}
// Create a bitmap
......@@ -58,24 +86,15 @@ GenericBitmap *BitmapFont::drawString( const UString &rString,
while( *pString )
{
uint32_t c = *(pString++);
int xSrc = -1;
if( c >= '0' && c <= '9' )
{
xSrc = (c - '0') * m_width;
}
else if( c == '-' )
{
xSrc = 11 * m_width;
}
if( xSrc != -1 )
if( c < 256 && m_table[c].m_xPos != -1 )
{
pBmp->drawBitmap( m_rBitmap, xSrc, 0, xDest, 0, m_width,
m_height );
xDest += m_width + 3;
pBmp->drawBitmap( m_rBitmap, m_table[c].m_xPos, m_table[c].m_yPos,
xDest, 0, m_width, m_height );
xDest += m_advance;
}
else
{
xDest += 6;
xDest += m_skip;
}
}
return pBmp;
......
......@@ -25,6 +25,7 @@
#define BITMAP_FONT_HPP
#include "generic_font.hpp"
#include <string>
class GenericBitmap;
......@@ -33,7 +34,8 @@ class GenericBitmap;
class BitmapFont: public GenericFont
{
public:
BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap );
BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
const string &rType );
virtual ~BitmapFont() {}
virtual bool init() { return true; }
......@@ -47,10 +49,23 @@ class BitmapFont: public GenericFont
virtual int getSize() const { return 12; }
private:
/// Description of a glyph
struct Glyph_t
{
Glyph_t(): m_xPos( -1 ), m_yPos( 0 ) {}
int m_xPos, m_yPos;
};
/// Bitmap
const GenericBitmap &m_rBitmap;
/// Glyph size
int m_width, m_height;
/// Horizontal advance between two characters
int m_advance;
/// Horizontal advance for non-displayable characters
int m_skip;
/// Character table
Glyph_t m_table[256];
};
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment