Problem with getting height on newText multiline on Android device

Hi all,

 

I use a custom font “Chalkduster.ttf” to make a text with mulitline function.

When I get the height or contentHeight in android device, the height is not correct.

 

I tested for other font, it can display the similar height in android device.

 

Does anyone have ideas on how can I use this font to get the correct height ?

 

local textFont = "Chalkduster" local textSize = 33 local posX = 100 local posY = 100 local offsetX = 100 local textWidth = 200 local stringData = { "single", "the height is larger in the android device" } for i=1, #stringData do local x = posX + textWidth \* (i - 1) + offsetX \* (i - 1) local y = posY local test = display.newText( stringData[i], x, y, textWidth, 0, textFont, textSize ) test.anchorX = 0 test.anchorY = 0 local width = test.contentWidth local height = test.contentHeight local resultString = "W: " .. width .. " H: " .. height local resultText = display.newText( resultString, x, y-50, textFont, textSize ) resultText.anchorX = 0 resultText.anchorY = 0 if ( i == 1 ) then resultText:setFillColor(1, 0, 0, 1) else resultText:setFillColor(0, 1, 1, 1) end local resultArea = display.newRect ( x, y, width, height ) resultArea.anchorX = 0 resultArea.anchorY = 0 resultArea.alpha = 0.5 if ( i == 1 ) then resultArea:setFillColor(1, 0, 0, 1) else resultArea:setFillColor(0, 1, 1, 1) end end

 

Attached with the captured image by simulator and android tablet device.

 

 

 

 

The link of the font: (Chalkduster.ttf)

http://www.sendspace.com/file/1pm2za

 

Thank for thanks.

 

Sam

What do you mean the height is not right?  Those values look reasonable.  Are you expecting the values to be the same?

Well that won’t happen.  The reason is Corona uses the device’s font rendering to generate the image we use for the font.  Every device and operating system have their own way of rendering fonts and you will never have the same results from the Mac OS vs. Windows OS. vs iOS OS vs. Google Android vs. Samsung  Android vs. Amazon Android.

They all process the font metrics just a little bit differently.

Thanks for your reply.

For the multiline text, I expect the height will be close to the visible text area.

I aim to use the height to calculate which character / line is touched, do you have any suggestion to do so ?

Thanks.

Can you output the text.height value and see if it’s different than text.contentHeight?

Just test and output to see,  text.height value and text.contentHeigth value are the same.

Sam, if you want the height /width of text to be consistent on all devices, use a bitmap font.

What do you mean the height is not right?  Those values look reasonable.  Are you expecting the values to be the same?

Well that won’t happen.  The reason is Corona uses the device’s font rendering to generate the image we use for the font.  Every device and operating system have their own way of rendering fonts and you will never have the same results from the Mac OS vs. Windows OS. vs iOS OS vs. Google Android vs. Samsung  Android vs. Amazon Android.

They all process the font metrics just a little bit differently.

Thanks for your reply.

For the multiline text, I expect the height will be close to the visible text area.

I aim to use the height to calculate which character / line is touched, do you have any suggestion to do so ?

Thanks.

Can you output the text.height value and see if it’s different than text.contentHeight?

Just test and output to see,  text.height value and text.contentHeigth value are the same.

Sam, if you want the height /width of text to be consistent on all devices, use a bitmap font.