diff options
| author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-09-06 11:23:43 +0200 | 
|---|---|---|
| committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-09-06 11:23:43 +0200 | 
| commit | b15870b7cb63316060a5ff565cf980a981633135 (patch) | |
| tree | 545db2d5a9acd193003ddc08bdd2ae0cf13c21b7 | |
| parent | acbeb0cc1b18c4f62ff8d1ac50adf6406235a36b (diff) | |
Fix crash when trying to display non ascii characters.
| -rw-r--r-- | plugingui/font.cc | 15 | ||||
| -rw-r--r-- | test/gui.cc | 45 | ||||
| -rw-r--r-- | test/paintertest.cc | 3 | 
3 files changed, 11 insertions, 52 deletions
| diff --git a/plugingui/font.cc b/plugingui/font.cc index 3be7dd5..a9b102e 100644 --- a/plugingui/font.cc +++ b/plugingui/font.cc @@ -26,13 +26,16 @@   */  #include "font.h" -namespace GUI { +#include <cassert> + +namespace GUI +{  Font::Font(const std::string& fontfile)  	: img_font(fontfile)  { -	size_t px = 0; -	size_t c; +	std::size_t px = 0; +	std::size_t c;  	for(c = 0; c < (characters.size() - 1) && px < img_font.width(); ++c)  	{ @@ -73,7 +76,7 @@ size_t Font::textWidth(const std::string& text) const  {  	size_t len = 0; -	for(auto cha : text) +	for(unsigned char cha : text)  	{  		auto& character = characters[cha];  		len += character.width + spacing + character.post_bias; @@ -103,9 +106,9 @@ PixelBufferAlpha *Font::render(const std::string& text) const  		new PixelBufferAlpha(textWidth(text), textHeight(text));  	int x_offset = 0; -	for(auto cha : text) +	for(unsigned char cha : text)  	{ -		auto& character = characters[cha]; +		auto& character = characters.at(cha);  		for(size_t x = 0; x < character.width; ++x)  		{  			for(size_t y = 0; y < img_font.height(); ++y) diff --git a/test/gui.cc b/test/gui.cc deleted file mode 100644 index 59e98b0..0000000 --- a/test/gui.cc +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - *            gui.cc - * - *  Fri Nov 29 18:08:57 CET 2013 - *  Copyright 2013 Bent Bisballe Nyeng - *  deva@aasimon.org - ****************************************************************************/ - -/* - *  This file is part of DrumGizmo. - * - *  DrumGizmo is free software; you can redistribute it and/or modify - *  it under the terms of the GNU Lesser General Public License as published by - *  the Free Software Foundation; either version 3 of the License, or - *  (at your option) any later version. - * - *  DrumGizmo is distributed in the hope that it will be useful, - *  but WITHOUT ANY WARRANTY; without even the implied warranty of - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - *  GNU Lesser General Public License for more details. - * - *  You should have received a copy of the GNU Lesser General Public License - *  along with DrumGizmo; if not, write to the Free Software - *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA. - */ -#include <cppunit/extensions/HelperMacros.h> - -class test_gui : public CppUnit::TestFixture -{ -  CPPUNIT_TEST_SUITE(test_gui); -	CPPUNIT_TEST(test1); -	CPPUNIT_TEST_SUITE_END(); - -public: -	void setUp() {} -	void tearDown() {} - -  void test1() { -	} -}; - -// Registers the fixture into the 'registry' -CPPUNIT_TEST_SUITE_REGISTRATION(test_gui); - diff --git a/test/paintertest.cc b/test/paintertest.cc index 5c8cf45..69b28ff 100644 --- a/test/paintertest.cc +++ b/test/paintertest.cc @@ -116,7 +116,8 @@ public:  	{  		// Success criterion is simply to not assert in the drawing routines...  		GUI::Font font; -		std::string someText = "Hello World"; +		// a string with unicode characters +		std::string someText = "Hello World - лæ";  		std::size_t width = font.textWidth(someText);  		std::size_t height = font.textHeight(someText); | 
