1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004 VideoLAN
7 * Authors: Cyril Deguet <asmax@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 #include "bitmap_font.hpp"
25 #include "generic_bitmap.hpp"
26 #include "../utils/ustring.hpp"
29 BitmapFont::BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
30 const string &rType ):
31 GenericFont( pIntf ), m_rBitmap( rBitmap )
33 // Build the character table
34 if( rType == "digits" )
40 for( int i = 0; i <= 9; i++ )
42 m_table['0'+i].m_xPos = i * m_width;
44 m_table[(size_t)'-'].m_xPos = 11 * m_width;
46 else if( rType == "text" )
52 for( int i = 0; i < 26; i++ )
54 m_table['A'+i].m_xPos = m_table['a'+i].m_xPos = i * m_width;
56 m_table[(size_t)'"'].m_xPos = 26 * m_width;
57 m_table[(size_t)'@'].m_xPos = 27 * m_width;
58 m_table[(size_t)' '].m_xPos = 29 * m_width;
59 for( int i = 0; i <= 9; i++ )
61 m_table['0'+i].m_xPos = i * m_width;
62 m_table['0'+i].m_yPos = m_height;
64 static const char specialChars[] = {'.', ':', '(', ')', '-', '\'',
65 '!', '_', '+', '\\', '/', '[', ']', '^', '&', '%', ',', '=', '$',
67 for( int i = 0; i < 19; i++ )
69 m_table[(size_t)specialChars[i]].m_xPos = (11 + i) * m_width;
70 m_table[(size_t)specialChars[i]].m_yPos = m_height;
72 m_table[(size_t)'?'].m_xPos = 4 * m_width;
73 m_table[(size_t)'*'].m_xPos = 5 * m_width;
74 m_table[(size_t)'?'].m_yPos = m_table[(size_t)'*'].m_yPos = 2 * m_height;
79 GenericBitmap *BitmapFont::drawString( const UString &rString,
80 uint32_t color, int maxWidth ) const
82 uint32_t *pString = (uint32_t*)rString.u_str();
83 // Compute the text width
85 for( uint32_t *ptr = pString; *ptr; ptr++ )
88 if( c < 256 && m_table[c].m_xPos != -1 )
98 BitmapImpl *pBmp = new BitmapImpl( getIntf(), width, m_height );
102 uint32_t c = *(pString++);
103 if( c < 256 && m_table[c].m_xPos != -1 )
105 pBmp->drawBitmap( m_rBitmap, m_table[c].m_xPos, m_table[c].m_yPos,
106 xDest, 0, m_width, m_height );