1 /*****************************************************************************
2  * bitmap_font.hpp
3  *****************************************************************************
4  * Copyright (C) 2004 the VideoLAN team
5  * $Id: 6f98480dd5fb3e0eae01099e71c56b317893136d $
6  *
7  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8  *
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.
13  *
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.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23 
24 #ifndef BITMAP_FONT_HPP
25 #define BITMAP_FONT_HPP
26 
27 #include "generic_font.hpp"
28 #include <string>
29 
30 class GenericBitmap;
31 
32 
33 /// Class to handle bitmap fonts
34 class BitmapFont: public GenericFont
35 {
36 public:
37     BitmapFont( intf_thread_t *pIntf, const GenericBitmap &rBitmap,
38                 const std::string &rType );
~BitmapFont()39     virtual ~BitmapFont() { }
40 
init()41     virtual bool init() { return true; }
42 
43     /// Render a string on a bitmap.
44     /// If maxWidth != -1, the text is truncated with '...'
45     virtual GenericBitmap *drawString( const UString &rString,
46         uint32_t color, int maxWidth = -1 ) const;
47 
48     /// Get the font size
getSize() const49     virtual int getSize() const { return m_height; }
50 
51 private:
52     /// Description of a glyph
53     struct Glyph_t
54     {
Glyph_tBitmapFont::Glyph_t55         Glyph_t(): m_xPos( -1 ), m_yPos( 0 ) { }
56         int m_xPos, m_yPos;
57     };
58 
59     /// Bitmap
60     const GenericBitmap &m_rBitmap;
61     /// Glyph size
62     int m_width, m_height;
63     /// Horizontal advance between two characters
64     int m_advance;
65     /// Horizontal advance for non-displayable characters
66     int m_skip;
67     /// Character table
68     Glyph_t m_table[256];
69 };
70 
71 #endif
72