mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
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:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user