Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

bitmap_font.cpp

00001 /*****************************************************************************
00002  * bitmap_font.cpp
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: bitmap_font.cpp 12501 2005-09-09 19:20:34Z gbazin $
00006  *
00007  * Authors: Cyril Deguet     <[email protected]>
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
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     // Build the character table
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     // Compute the text width
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     // Create a bitmap
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 

Generated on Tue Dec 20 10:14:42 2005 for vlc-0.8.4a by  doxygen 1.4.2