[657] | 1 | /*-------------------------------------------------------------------------
|
---|
| 2 | This source file is a part of OGRE
|
---|
| 3 | (Object-oriented Graphics Rendering Engine)
|
---|
| 4 |
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This library is free software; you can redistribute it and/or modify it
|
---|
| 11 | under the terms of the GNU Lesser General Public License (LGPL) as
|
---|
| 12 | published by the Free Software Foundation; either version 2.1 of the
|
---|
| 13 | License, or (at your option) any later version.
|
---|
| 14 |
|
---|
| 15 | This library is distributed in the hope that it will be useful, but
|
---|
| 16 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
---|
| 17 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
---|
| 18 | License for more details.
|
---|
| 19 |
|
---|
| 20 | You should have received a copy of the GNU Lesser General Public License
|
---|
| 21 | along with this library; if not, write to the Free Software Foundation,
|
---|
| 22 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or go to
|
---|
| 23 | http://www.gnu.org/copyleft/lesser.txt
|
---|
| 24 | -------------------------------------------------------------------------*/
|
---|
| 25 | #include "OgreStableHeaders.h"
|
---|
| 26 |
|
---|
| 27 | #include "OgreFontManager.h"
|
---|
| 28 | #include "OgreLogManager.h"
|
---|
| 29 | #include "OgreStringConverter.h"
|
---|
| 30 | #include "OgreStringVector.h"
|
---|
| 31 | #include "OgreException.h"
|
---|
| 32 | #include "OgreResourceGroupManager.h"
|
---|
| 33 |
|
---|
| 34 | namespace Ogre
|
---|
| 35 | {
|
---|
| 36 | //---------------------------------------------------------------------
|
---|
| 37 | template<> FontManager * Singleton< FontManager >::ms_Singleton = 0;
|
---|
| 38 | FontManager* FontManager::getSingletonPtr(void)
|
---|
| 39 | {
|
---|
| 40 | return ms_Singleton;
|
---|
| 41 | }
|
---|
| 42 | FontManager& FontManager::getSingleton(void)
|
---|
| 43 | {
|
---|
| 44 | assert( ms_Singleton ); return ( *ms_Singleton );
|
---|
| 45 | }
|
---|
| 46 | //---------------------------------------------------------------------
|
---|
| 47 | FontManager::FontManager() : ResourceManager()
|
---|
| 48 | {
|
---|
| 49 | // Loading order
|
---|
| 50 | mLoadOrder = 200.0f;
|
---|
| 51 | // Scripting is supported by this manager
|
---|
| 52 | mScriptPatterns.push_back("*.fontdef");
|
---|
| 53 | // Register scripting with resource group manager
|
---|
| 54 | ResourceGroupManager::getSingleton()._registerScriptLoader(this);
|
---|
| 55 |
|
---|
| 56 | // Resource type
|
---|
| 57 | mResourceType = "Font";
|
---|
| 58 |
|
---|
| 59 | // Register with resource group manager
|
---|
| 60 | ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | }
|
---|
| 64 | //---------------------------------------------------------------------
|
---|
| 65 | FontManager::~FontManager()
|
---|
| 66 | {
|
---|
| 67 | // Unregister with resource group manager
|
---|
| 68 | ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
|
---|
| 69 | // Unegister scripting with resource group manager
|
---|
| 70 | ResourceGroupManager::getSingleton()._unregisterScriptLoader(this);
|
---|
| 71 |
|
---|
| 72 | }
|
---|
| 73 | //---------------------------------------------------------------------
|
---|
| 74 | Resource* FontManager::createImpl(const String& name, ResourceHandle handle,
|
---|
| 75 | const String& group, bool isManual, ManualResourceLoader* loader,
|
---|
| 76 | const NameValuePairList* params)
|
---|
| 77 | {
|
---|
| 78 | return new Font(this, name, handle, group, isManual, loader);
|
---|
| 79 | }
|
---|
| 80 | //---------------------------------------------------------------------
|
---|
| 81 | void FontManager::parseScript(DataStreamPtr& stream, const String& groupName)
|
---|
| 82 | {
|
---|
| 83 | String line;
|
---|
| 84 | FontPtr pFont;
|
---|
| 85 |
|
---|
| 86 | while( !stream->eof() )
|
---|
| 87 | {
|
---|
| 88 | line = stream->getLine();
|
---|
| 89 | // Ignore blanks & comments
|
---|
| 90 | if( !line.length() || line.substr( 0, 2 ) == "//" )
|
---|
| 91 | {
|
---|
| 92 | continue;
|
---|
| 93 | }
|
---|
| 94 | else
|
---|
| 95 | {
|
---|
| 96 | if (pFont.isNull())
|
---|
| 97 | {
|
---|
| 98 | // No current font
|
---|
| 99 | // So first valid data should be font name
|
---|
| 100 | pFont = create(line, groupName);
|
---|
| 101 | pFont->_notifyOrigin(stream->getName());
|
---|
| 102 | // Skip to and over next {
|
---|
| 103 | stream->skipLine("{");
|
---|
| 104 | }
|
---|
| 105 | else
|
---|
| 106 | {
|
---|
| 107 | // Already in font
|
---|
| 108 | if (line == "}")
|
---|
| 109 | {
|
---|
| 110 | // Finished
|
---|
| 111 | pFont.setNull();
|
---|
| 112 | // NB font isn't loaded until required
|
---|
| 113 | }
|
---|
| 114 | else
|
---|
| 115 | {
|
---|
| 116 | parseAttribute(line, pFont);
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | //---------------------------------------------------------------------
|
---|
| 123 | void FontManager::parseAttribute(const String& line, FontPtr& pFont)
|
---|
| 124 | {
|
---|
| 125 | std::vector<String> params = StringUtil::split(line);
|
---|
| 126 | String& attrib = params[0];
|
---|
| 127 | StringUtil::toLowerCase(attrib);
|
---|
| 128 | if (attrib == "type")
|
---|
| 129 | {
|
---|
| 130 | // Check params
|
---|
| 131 | if (params.size() != 2)
|
---|
| 132 | {
|
---|
| 133 | logBadAttrib(line, pFont);
|
---|
| 134 | return;
|
---|
| 135 | }
|
---|
| 136 | // Set
|
---|
| 137 | StringUtil::toLowerCase(params[1]);
|
---|
| 138 | if (params[1] == "truetype")
|
---|
| 139 | {
|
---|
| 140 | pFont->setType(FT_TRUETYPE);
|
---|
| 141 | }
|
---|
| 142 | else
|
---|
| 143 | {
|
---|
| 144 | pFont->setType(FT_IMAGE);
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | }
|
---|
| 148 | else if (attrib == "source")
|
---|
| 149 | {
|
---|
| 150 | // Check params
|
---|
| 151 | if (params.size() != 2)
|
---|
| 152 | {
|
---|
| 153 | logBadAttrib(line, pFont);
|
---|
| 154 | return;
|
---|
| 155 | }
|
---|
| 156 | // Set
|
---|
| 157 | pFont->setSource(params[1]);
|
---|
| 158 | }
|
---|
| 159 | else if (attrib == "glyph")
|
---|
| 160 | {
|
---|
| 161 | // Check params
|
---|
| 162 | if (params.size() != 6)
|
---|
| 163 | {
|
---|
| 164 | logBadAttrib(line, pFont);
|
---|
| 165 | return;
|
---|
| 166 | }
|
---|
| 167 | // Set
|
---|
| 168 | pFont->setGlyphTexCoords(
|
---|
| 169 | params[1].at(0),
|
---|
| 170 | StringConverter::parseReal(params[2]),
|
---|
| 171 | StringConverter::parseReal(params[3]),
|
---|
| 172 | StringConverter::parseReal(params[4]),
|
---|
| 173 | StringConverter::parseReal(params[5]) );
|
---|
| 174 | }
|
---|
| 175 | else if (attrib == "size")
|
---|
| 176 | {
|
---|
| 177 | // Check params
|
---|
| 178 | if (params.size() != 2)
|
---|
| 179 | {
|
---|
| 180 | logBadAttrib(line, pFont);
|
---|
| 181 | return;
|
---|
| 182 | }
|
---|
| 183 | // Set
|
---|
| 184 | pFont->setTrueTypeSize(
|
---|
| 185 | StringConverter::parseReal(params[1]) );
|
---|
| 186 | }
|
---|
| 187 | else if (attrib == "resolution")
|
---|
| 188 | {
|
---|
| 189 | // Check params
|
---|
| 190 | if (params.size() != 2)
|
---|
| 191 | {
|
---|
| 192 | logBadAttrib(line, pFont);
|
---|
| 193 | return;
|
---|
| 194 | }
|
---|
| 195 | // Set
|
---|
| 196 | pFont->setTrueTypeResolution(
|
---|
| 197 | (uint)StringConverter::parseReal(params[1]) );
|
---|
| 198 | }
|
---|
| 199 | else if (attrib == "antialias_colour")
|
---|
| 200 | {
|
---|
| 201 | // Check params
|
---|
| 202 | if (params.size() != 2)
|
---|
| 203 | {
|
---|
| 204 | logBadAttrib(line, pFont);
|
---|
| 205 | return;
|
---|
| 206 | }
|
---|
| 207 | // Set
|
---|
| 208 | pFont->setAntialiasColour(StringConverter::parseBool(params[1]));
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | }
|
---|
| 214 | //---------------------------------------------------------------------
|
---|
| 215 | void FontManager::logBadAttrib(const String& line, FontPtr& pFont)
|
---|
| 216 | {
|
---|
| 217 | LogManager::getSingleton().logMessage("Bad attribute line: " + line +
|
---|
| 218 | " in font " + pFont->getName());
|
---|
| 219 |
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | }
|
---|