diff options
| author | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-09-06 14:24:41 +0200 | 
|---|---|---|
| committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2016-09-06 14:24:41 +0200 | 
| commit | 8717bae5f4a141911ba58b34b6ac630780e089ed (patch) | |
| tree | 75619c95b7f536a560c81e6da5f45a89f4c1438c /plugingui | |
| parent | 4de65ee303837504e6c05f5d71d94c8b23a0270d (diff) | |
Fix another crash in the font renderer.
Diffstat (limited to 'plugingui')
| -rw-r--r-- | plugingui/font.cc | 18 | ||||
| -rw-r--r-- | plugingui/font.h | 4 | 
2 files changed, 16 insertions, 6 deletions
| diff --git a/plugingui/font.cc b/plugingui/font.cc index a9b102e..a56d392 100644 --- a/plugingui/font.cc +++ b/plugingui/font.cc @@ -44,8 +44,12 @@ Font::Font(const std::string& fontfile)  		if(c > 0)  		{ -			characters[c - 1].width = -				character.offset - characters[c - 1].offset - 1; +			assert(character.offset >= characters[c - 1].offset); +			characters[c - 1].width = character.offset - characters[c - 1].offset; +			if(characters[c].offset != characters[c - 1].offset) +			{ +				--characters[c - 1].width; +			}  		}  		++px; @@ -69,7 +73,12 @@ Font::Font(const std::string& fontfile)  	++c; -	characters[c - 1].width = characters[c].offset - characters[c - 1].offset - 1; +	assert(characters[c].offset >= characters[c - 1].offset); +	characters[c - 1].width = characters[c].offset - characters[c - 1].offset; +	if(characters[c].offset != characters[c - 1].offset) +	{ +		--characters[c - 1].width; +	}  }  size_t Font::textWidth(const std::string& text) const @@ -106,8 +115,9 @@ PixelBufferAlpha *Font::render(const std::string& text) const  		new PixelBufferAlpha(textWidth(text), textHeight(text));  	int x_offset = 0; -	for(unsigned char cha : text) +	for(std::size_t i = 0; i < text.length(); ++i)  	{ +		unsigned char cha = text[i];  		auto& character = characters.at(cha);  		for(size_t x = 0; x < character.width; ++x)  		{ diff --git a/plugingui/font.h b/plugingui/font.h index e18f1bd..84e1f63 100644 --- a/plugingui/font.h +++ b/plugingui/font.h @@ -51,8 +51,8 @@ private:  	class Character {  	public: -		int offset{0}; -		size_t width{0}; +		std::size_t offset{0}; +		std::size_t width{0};  		int pre_bias{0};  		int post_bias{0};  	}; | 
