creating a font with faulty data now throws an exception; error handler now wraps error text if it's too long

This commit is contained in:
bill@Ixion
2009-08-28 20:45:20 -05:00
parent 0e0c7527b1
commit 5850700c8e
4 changed files with 65 additions and 54 deletions
+25 -21
View File
@@ -1,27 +1,28 @@
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
/**
* Copyright (c) 2006-2009 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "TrueTypeFont.h"
#include <SDL_opengl.h>
#include <common/Exception.h>
#include <math.h>
#include <iostream>
@@ -207,16 +208,19 @@ namespace opengl
for(unsigned int i = 0; i != MAX_CHARS; i++) widths[i] = 0;
FT_Library library;
if( FT_Init_FreeType(&library) )
if( FT_Init_FreeType(&library) ) {
std::cerr << "TrueTypeFont Loading error: FT_Init_FreeType failed." << std::endl;
throw love::Exception("TrueTypeFont Loading error: FT_Init_FreeType failed.");
}
FT_Face face;
if( FT_New_Memory_Face( library,
(const FT_Byte *)data->getData(), /* first byte in memory */
data->getSize(), /* size in bytes */
0, /* face_index */
&face ))
&face )) {
std::cerr << "TrueTypeFont Loading error: FT_New_Face failed (there is probably a problem with your font file)." << std::endl;
throw love::Exception("TrueTypeFont Loading error: FT_New_Face failed (there is probably a problem with your font file).");
}
//FT_Set_Char_Size(face, size << 6, size << 6, 96, 96);
FT_Set_Pixel_Sizes(face, size, size);
@@ -210,7 +210,12 @@ namespace opengl
// Second optional parameter can be a number:
int size = luaL_optint(L, 2, 12);
Font * font = instance->newFont(d, size);
Font * font;
try {
font = instance->newFont(d, size);
} catch (Exception & e) {
return luaL_error(L, e.what());
}
if(font == 0)
return luaL_error(L, "Could not load the font");