font:getWrap - Bug?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Chronoc
Prole
Posts: 5
Joined: Tue Jul 29, 2014 3:26 pm
Location: Germany

font:getWrap - Bug?

Post 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 2113 times
Can someone please explain me, where the mistake is?

cu
Chronoc
Attachments
fontGetWrapProblem.zip
main.lua, used ttf and screenshot
(34.23 KiB) Downloaded 68 times
User avatar
slime
Solid Snayke
Posts: 3132
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: font:getWrap - Bug?

Post 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.
User avatar
Chronoc
Prole
Posts: 5
Joined: Tue Jul 29, 2014 3:26 pm
Location: Germany

Re: font:getWrap - Bug?

Post by Chronoc »

Thank you :)
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 181 guests