1 /************************************************************************
2  *                                                                      *
3  *  FreeSynd - a remake of the classic Bullfrog game "Syndicate".       *
4  *                                                                      *
5  *   Copyright (C) 2005  Stuart Binge  <skbinge@gmail.com>              *
6  *   Copyright (C) 2005  Joost Peters  <joostp@users.sourceforge.net>   *
7  *   Copyright (C) 2006  Trent Waddington <qg@biodome.org>              *
8  *   Copyright (C) 2006  Tarjei Knapstad <tarjei.knapstad@gmail.com>    *
9  *   Copyright (C) 2011  Joey Parrish  <joey.parrish@gmail.com>         *
10  *   Copyright (C) 2011  Benoit Blancard <benblan@users.sourceforge.net>*
11  *                                                                      *
12  *    This program is free software;  you can redistribute it and / or  *
13  *  modify it  under the  terms of the  GNU General  Public License as  *
14  *  published by the Free Software Foundation; either version 2 of the  *
15  *  License, or (at your option) any later version.                     *
16  *                                                                      *
17  *    This program is  distributed in the hope that it will be useful,  *
18  *  but WITHOUT  ANY WARRANTY;  without even  the implied  warranty of  *
19  *  MERCHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  *
20  *  General Public License for more details.                            *
21  *                                                                      *
22  *    You can view the GNU  General Public License, online, at the GNU  *
23  *  project's  web  site;  see <http://www.gnu.org/licenses/gpl.html>.  *
24  *  The full text of the license is also included in the file COPYING.  *
25  *                                                                      *
26  ************************************************************************/
27 
28 #include <stdio.h>
29 #include <assert.h>
30 #include "fontmanager.h"
31 
FontManager()32 FontManager::FontManager()
33 {
34     for (int i = 0; i < 4; i++)
35         menuFonts_[i] = NULL;
36 
37     pIntroFont_ = NULL;
38     pGameFont_ = NULL;
39 }
40 
~FontManager()41 FontManager::~FontManager()
42 {
43     for (int i = 0; i < 4; i++) {
44         delete menuFonts_[i];
45     }
46 
47     if (pIntroFont_) {
48         delete pIntroFont_;
49     }
50     if (pGameFont_)
51         delete pGameFont_;
52 }
53 
loadFonts(SpriteManager * pMenuSprites,SpriteManager * pIntroFontSprites_)54 bool FontManager::loadFonts(SpriteManager *pMenuSprites, SpriteManager *pIntroFontSprites_) {
55     assert(pMenuSprites);
56 
57     menuFonts_[SIZE_4] = createMenuFontForSize(pMenuSprites, FontManager::SIZE_4, 1076, 939, 'A', "0x27,0x2c-0x2f,0x41-0x5a,0x5c,0x60,0x80-0x90,0x93-0x9a,0xa0-0xa7");
58     menuFonts_[SIZE_3] = createMenuFontForSize(pMenuSprites, FontManager::SIZE_3, 802, 665, 'A', "0x21-0x5a,0x80-0x90,0x93-0x9a,0xa0-0xa8");
59     menuFonts_[SIZE_2] = createMenuFontForSize(pMenuSprites, FontManager::SIZE_2, 528, 391, 'A', "0x21-0x60,0x80-0xa8");
60     menuFonts_[SIZE_1] = createMenuFontForSize(pMenuSprites, FontManager::SIZE_1, 254, 117, 'A', "0x21-0x60,0x80-0xa8");
61 
62     pGameFont_ = new GameFont();
63     pGameFont_->setSpriteManager(pMenuSprites, 665, 'A', "0x21-0x5a,0x80-0x90,0x93-0x9a,0xa0-0xa8");
64 
65     if (pIntroFontSprites_) {
66         pIntroFont_ = new Font();
67         pIntroFont_->setSpriteManager(pIntroFontSprites_, 1, '!', "0x21-0x60,0x80-0xa8");
68     }
69 
70     return true;
71 }
72 
createMenuFontForSize(SpriteManager * sprites,EFontSize size,int darkOffset,int lightOffset,char base,const std::string & valid_chars)73 MenuFont * FontManager::createMenuFontForSize(SpriteManager * sprites, EFontSize size,
74                            int darkOffset, int lightOffset, char base, const std::string& valid_chars)
75 {
76     MenuFont * pFont = new MenuFont();
77     pFont->setSpriteManager(sprites, darkOffset, lightOffset, base, valid_chars);
78 
79     return pFont;
80 }
81 
82