Browse Source

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

bill@Ixion 16 years ago
parent
commit
5850700c8e

+ 25 - 21
src/modules/graphics/opengl/TrueTypeFont.cpp

@@ -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);
 

+ 6 - 1
src/modules/graphics/opengl/wrap_Graphics.cpp

@@ -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");

+ 1 - 1
src/scripts/boot.lua

@@ -666,7 +666,7 @@ function love.errhand(msg)
 	p = string.gsub(p, "\t", "")
 	p = string.gsub(p, "%[string \"(.-)\"%]", "%1")
 	
-	love.graphics.print(p, 70, 70)	
+	love.graphics.printf(p, 70, 70, love.graphics.getWidth() - 70)	
 	
 	love.graphics.present()
 		

+ 33 - 31
src/scripts/boot.lua.h

@@ -716,42 +716,44 @@ static const unsigned char B1[]={
 114,105,110,103, 46,103,115,117, 98, 40,112, 44, 32, 34, 37, 91,115,116,114,105,
 110,103, 32, 92, 34, 40, 46, 45, 41, 92, 34, 37, 93, 34, 44, 32, 34, 37, 49, 34,
  41, 13, 10,  9, 13, 10,  9,108,111,118,101, 46,103,114, 97,112,104,105, 99,115,
- 46,112,114,105,110,116, 40,112, 44, 32, 55, 48, 44, 32, 55, 48, 41,  9, 13, 10,
-  9, 13, 10,  9,108,111,118,101, 46,103,114, 97,112,104,105, 99,115, 46,112,114,
-101,115,101,110,116, 40, 41, 13, 10,  9,  9, 13, 10,  9,119,104,105,108,101, 32,
-116,114,117,101, 32,100,111, 13, 10,  9,  9,101, 44, 32, 97, 44, 32, 98, 44, 32,
- 99, 32, 61, 32,108,111,118,101, 46,101,118,101,110,116, 46,119, 97,105,116, 40,
- 41, 13, 10,  9,  9, 13, 10,  9,  9,105,102, 32,101, 32, 61, 61, 32,108,111,118,
-101, 46,101,118,101,110,116, 95,113,117,105,116, 32,116,104,101,110, 32,114,101,
-116,117,114,110, 32,101,110,100, 13, 10,  9,  9,105,102, 32,101, 32, 61, 61, 32,
-108,111,118,101, 46,101,118,101,110,116, 95,107,101,121,112,114,101,115,115,101,
-100, 32, 97,110,100, 32, 97, 32, 61, 61, 32,108,111,118,101, 46,107,101,121, 95,
-101,115, 99, 97,112,101, 32,116,104,101,110, 13, 10,  9,  9,  9,114,101,116,117,
-114,110, 13, 10,  9,  9,101,110,100, 13, 10, 13, 10,  9,101,110,100, 13, 10,  9,
- 13, 10,101,110,100, 13, 10, 13, 10, 13, 10, 45, 45, 45, 45, 45, 45, 45, 45, 45,
+ 46,112,114,105,110,116,102, 40,112, 44, 32, 55, 48, 44, 32, 55, 48, 44, 32,108,
+111,118,101, 46,103,114, 97,112,104,105, 99,115, 46,103,101,116, 87,105,100,116,
+104, 40, 41, 32, 45, 32, 55, 48, 41,  9, 13, 10,  9, 13, 10,  9,108,111,118,101,
+ 46,103,114, 97,112,104,105, 99,115, 46,112,114,101,115,101,110,116, 40, 41, 13,
+ 10,  9,  9, 13, 10,  9,119,104,105,108,101, 32,116,114,117,101, 32,100,111, 13,
+ 10,  9,  9,101, 44, 32, 97, 44, 32, 98, 44, 32, 99, 32, 61, 32,108,111,118,101,
+ 46,101,118,101,110,116, 46,119, 97,105,116, 40, 41, 13, 10,  9,  9, 13, 10,  9,
+  9,105,102, 32,101, 32, 61, 61, 32,108,111,118,101, 46,101,118,101,110,116, 95,
+113,117,105,116, 32,116,104,101,110, 32,114,101,116,117,114,110, 32,101,110,100,
+ 13, 10,  9,  9,105,102, 32,101, 32, 61, 61, 32,108,111,118,101, 46,101,118,101,
+110,116, 95,107,101,121,112,114,101,115,115,101,100, 32, 97,110,100, 32, 97, 32,
+ 61, 61, 32,108,111,118,101, 46,107,101,121, 95,101,115, 99, 97,112,101, 32,116,
+104,101,110, 13, 10,  9,  9,  9,114,101,116,117,114,110, 13, 10,  9,  9,101,110,
+100, 13, 10, 13, 10,  9,101,110,100, 13, 10,  9, 13, 10,101,110,100, 13, 10, 13,
+ 10, 13, 10, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
  45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
  45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 13, 10, 45, 45, 32, 84,104,101, 32,114,
-111,111,116, 32,111,102, 32, 97,108,108, 32, 99, 97,108,108,115, 46, 13, 10, 45,
+ 45, 45, 13, 10, 45, 45, 32, 84,104,101, 32,114,111,111,116, 32,111,102, 32, 97,
+108,108, 32, 99, 97,108,108,115, 46, 13, 10, 45, 45, 45, 45, 45, 45, 45, 45, 45,
  45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
  45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
- 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 13, 10,
- 13, 10,102,117,110, 99,116,105,111,110, 32,101,114,114,111,114, 95,112,114,105,
-110,116,101,114, 40,109,115,103, 41, 13, 10,  9,112,114,105,110,116, 40, 34, 98,
-111,111,116, 34, 44, 32,109,115,103, 44, 32,100,101, 98,117,103, 46,116,114, 97,
- 99,101, 98, 97, 99,107, 40, 41, 41, 13, 10,101,110,100, 13, 10, 13, 10,114,101,
-115,117,108,116, 32, 61, 32,120,112, 99, 97,108,108, 40,108,111,118,101, 46, 98,
-111,111,116, 44, 32,101,114,114,111,114, 95,112,114,105,110,116,101,114, 41, 13,
- 10,105,102, 32,110,111,116, 32,114,101,115,117,108,116, 32,116,104,101,110, 32,
-114,101,116,117,114,110, 32,101,110,100, 13, 10,114,101,115,117,108,116, 32, 61,
- 32,120,112, 99, 97,108,108, 40,108,111,118,101, 46,105,110,105,116, 44, 32,108,
-111,118,101, 46,101,114,114,104, 97,110,100, 41, 13, 10,105,102, 32,110,111,116,
- 32,114,101,115,117,108,116, 32,116,104,101,110, 32,114,101,116,117,114,110, 32,
-101,110,100, 13, 10,114,101,115,117,108,116, 32, 61, 32,120,112, 99, 97,108,108,
- 40,108,111,118,101, 46,114,117,110, 44, 32,108,111,118,101, 46,101,114,114,104,
+ 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 13, 10, 13, 10,102,117,110, 99,116,105,
+111,110, 32,101,114,114,111,114, 95,112,114,105,110,116,101,114, 40,109,115,103,
+ 41, 13, 10,  9,112,114,105,110,116, 40, 34, 98,111,111,116, 34, 44, 32,109,115,
+103, 44, 32,100,101, 98,117,103, 46,116,114, 97, 99,101, 98, 97, 99,107, 40, 41,
+ 41, 13, 10,101,110,100, 13, 10, 13, 10,114,101,115,117,108,116, 32, 61, 32,120,
+112, 99, 97,108,108, 40,108,111,118,101, 46, 98,111,111,116, 44, 32,101,114,114,
+111,114, 95,112,114,105,110,116,101,114, 41, 13, 10,105,102, 32,110,111,116, 32,
+114,101,115,117,108,116, 32,116,104,101,110, 32,114,101,116,117,114,110, 32,101,
+110,100, 13, 10,114,101,115,117,108,116, 32, 61, 32,120,112, 99, 97,108,108, 40,
+108,111,118,101, 46,105,110,105,116, 44, 32,108,111,118,101, 46,101,114,114,104,
  97,110,100, 41, 13, 10,105,102, 32,110,111,116, 32,114,101,115,117,108,116, 32,
-116,104,101,110, 32,114,101,116,117,114,110, 32,101,110,100, 13, 10, 13, 10,112,
-114,105,110,116, 40, 34, 68,111,110,101, 46, 34, 41, 13, 10,
+116,104,101,110, 32,114,101,116,117,114,110, 32,101,110,100, 13, 10,114,101,115,
+117,108,116, 32, 61, 32,120,112, 99, 97,108,108, 40,108,111,118,101, 46,114,117,
+110, 44, 32,108,111,118,101, 46,101,114,114,104, 97,110,100, 41, 13, 10,105,102,
+ 32,110,111,116, 32,114,101,115,117,108,116, 32,116,104,101,110, 32,114,101,116,
+117,114,110, 32,101,110,100, 13, 10, 13, 10,112,114,105,110,116, 40, 34, 68,111,
+110,101, 46, 34, 41, 13, 10,
 };
 
  if (luaL_loadbuffer(L,(const char*)B1,sizeof(B1),"boot.lua")==0) lua_pcall(L, 0, 0, 0);