Page 1 of 1

font:getWrap - Bug?

Posted: Tue Jul 29, 2014 3:43 pm
by Chronoc
Hi,

I have a problem with font:getWrap, and I don't know if it is a bug or is it me, who doesn't understand the mechanics of löve...

Description:
Using a ttf (Comic Neue Regular (included in attachment), but the problem is not limited to this font), I want to draw a long text with a limited width using printf. But when I try to get the needed width and height for the text, the gotten width is to small, the height to big, and the lines are not the same displayed...

Code: Select all

function love.load()
	text = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor.';	
	font = love.graphics.newFont( 'ComicNeue-Regular.ttf', 19 );
	limit = 300;
end

function love.draw()
	width, lines = font:getWrap( text, limit );
	height = lines * font:getLineHeight() * font:getHeight();

	love.graphics.setColor{ 128, 128, 128, 255 };
	love.graphics.rectangle( 'fill', 0, 0, width, height );

	love.graphics.setColor{ 255, 255, 255, 255 };
	love.graphics.printf( text, 0, 0, limit );
end
Actually there are 11 lines displayed, but getWrap says, there are 15 lines?
screenshot.png
screenshot.png (13.93 KiB) Viewed 2191 times
Can someone please explain me, where the mistake is?

cu
Chronoc

Re: font:getWrap - Bug?

Posted: Tue Jul 29, 2014 3:59 pm
by slime
You need to set the Font object as the current font (using love.graphics.setFont) before calling love.graphics.printf.

If you use love.graphics.setNewFont rather than love.graphics.newFont, it will do love.graphics.newFont and love.graphics.setFont all in one call.

Re: font:getWrap - Bug?

Posted: Tue Jul 29, 2014 4:52 pm
by Chronoc
Thank you :)