1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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 )
35 // Build the character table
36 if( rType == "digits" )
42 for( i = 0; i <= 9; i++ )
44 m_table['0'+i].m_xPos = i * m_width;
46 m_table[(size_t)' '].m_xPos = 10 * m_width;
47 m_table[(size_t)'-'].m_xPos = 11 * m_width;
49 else if( rType == "text" )
55 for( i = 0; i < 26; i++ )
57 m_table['A'+i].m_xPos = m_table['a'+i].m_xPos = i * m_width;
59 m_table[(size_t)'"'].m_xPos = 26 * m_width;
60 m_table[(size_t)'@'].m_xPos = 27 * m_width;
61 m_table[(size_t)' '].m_xPos = 29 * m_width;
62 for( i = 0; i <= 9; i++ )
64 m_table['0'+i].m_xPos = i * m_width;
65 m_table['0'+i].m_yPos = m_height;
67 static const char specialChars[] = {'.', ':', '(', ')', '-', '\'',
68 '!', '_', '+', '\\', '/', '[', ']', '^', '&', '%', ',', '=', '$',
70 for( i = 0; i < 19; i++ )
72 m_table[(size_t)specialChars[i]].m_xPos = (11 + i) * m_width;
73 m_table[(size_t)specialChars[i]].m_yPos = m_height;
75 m_table[(size_t)'?'].m_xPos = 4 * m_width;
76 m_table[(size_t)'*'].m_xPos = 5 * m_width;
77 m_table[(size_t)'?'].m_yPos = m_table[(size_t)'*'].m_yPos = 2 * m_height;
82 GenericBitmap *BitmapFont::drawString( const UString &rString,
83 uint32_t color, int maxWidth ) const
85 uint32_t *pString = (uint32_t*)rString.u_str();
86 // Compute the text width
88 for( uint32_t *ptr = pString; *ptr; ptr++ )
91 if( c < 256 && m_table[c].m_xPos != -1 )
101 BitmapImpl *pBmp = new BitmapImpl( getIntf(), width, m_height );
105 uint32_t c = *(pString++);
106 if( c < 256 && m_table[c].m_xPos != -1 )
108 bool res = pBmp->drawBitmap( m_rBitmap, m_table[c].m_xPos,
109 m_table[c].m_yPos, xDest, 0,
112 msg_Warn( getIntf(), "BitmapFont::drawString: ignoring char" );