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 ) ...@@ -144,7 +144,7 @@ void Builder::addBitmapFont( const BuilderData::BitmapFont &rData )
GenericBitmap *pBmp = new PngBitmap( getIntf(), rData.m_file, 0 ); GenericBitmap *pBmp = new PngBitmap( getIntf(), rData.m_file, 0 );
m_pTheme->m_bitmaps[rData.m_id] = GenericBitmapPtr( pBmp ); 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() ) if( pFont->init() )
{ {
m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont ); m_pTheme->m_fonts[rData.m_id] = GenericFontPtr( pFont );
......
...@@ -26,11 +26,39 @@ ...@@ -26,11 +26,39 @@
#include "../utils/ustring.hpp" #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 ) GenericFont( pIntf ), m_rBitmap( rBitmap )
{ {
if( rType == "digits" )
{
m_width = 9; m_width = 9;
m_height = 13; 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, ...@@ -43,13 +71,13 @@ GenericBitmap *BitmapFont::drawString( const UString &rString,
for( uint32_t *ptr = pString; *ptr; ptr++ ) for( uint32_t *ptr = pString; *ptr; ptr++ )
{ {
uint32_t c = *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 else
{ {
width += 6; width += m_skip;
} }
} }
// Create a bitmap // Create a bitmap
...@@ -58,24 +86,15 @@ GenericBitmap *BitmapFont::drawString( const UString &rString, ...@@ -58,24 +86,15 @@ GenericBitmap *BitmapFont::drawString( const UString &rString,
while( *pString ) while( *pString )
{ {
uint32_t c = *(pString++); uint32_t c = *(pString++);
int xSrc = -1; if( c < 256 && m_table[c].m_xPos != -1 )
if( c >= '0' && c <= '9' )
{
xSrc = (c - '0') * m_width;
}
else if( c == '-' )
{
xSrc = 11 * m_width;
}
if( xSrc != -1 )
{ {
pBmp->drawBitmap( m_rBitmap, xSrc, 0, xDest, 0, m_width, pBmp->drawBitmap( m_rBitmap, m_table[c].m_xPos, m_table[c].m_yPos,
m_height ); xDest, 0, m_width, m_height );
xDest += m_width + 3; xDest += m_advance;
} }
else else
{ {
xDest += 6; xDest += m_skip;
} }
} }
return pBmp; return pBmp;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#define BITMAP_FONT_HPP #define BITMAP_FONT_HPP
#include "generic_font.hpp" #include "generic_font.hpp"
#include <string>
class GenericBitmap; class GenericBitmap;
...@@ -33,7 +34,8 @@ class GenericBitmap; ...@@ -33,7 +34,8 @@ class GenericBitmap;
class BitmapFont: public GenericFont class BitmapFont: public GenericFont
{ {
public: public:
BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap ); BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
const string &rType );
virtual ~BitmapFont() {} virtual ~BitmapFont() {}
virtual bool init() { return true; } virtual bool init() { return true; }
...@@ -47,10 +49,23 @@ class BitmapFont: public GenericFont ...@@ -47,10 +49,23 @@ class BitmapFont: public GenericFont
virtual int getSize() const { return 12; } virtual int getSize() const { return 12; }
private: private:
/// Description of a glyph
struct Glyph_t
{
Glyph_t(): m_xPos( -1 ), m_yPos( 0 ) {}
int m_xPos, m_yPos;
};
/// Bitmap /// Bitmap
const GenericBitmap &m_rBitmap; const GenericBitmap &m_rBitmap;
/// Glyph size /// Glyph size
int m_width, m_height; 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 #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