display.newText bug! (only on android)

I found a bug on display.newText.

tried with latest builds.

the code i tried was:

local bug="Line1.\nLine2.\nLine3.\nLine4.\nLine5.\nLine6.\nLine7.\nline8.\nline9\nline10\nline11\nline12\nline13\nline14" local params={ text=bug, font = native.systemFontBold, fontSize = 12, width=120, align="left" } local group=display.newGroup() local someText=display.newText(params) someText.anchorX=0 someText.anchorY=0 local back=display.newRect(0,0,someText.contentWidth,someText.contentHeight) back.anchorX=0 back.anchorY=0 back:setFillColor(0.4,0.4,0.4,1) group:insert(back) group:insert(someText) group:translate(display.contentWidth\*.5, display.contentHeight\*.5)

in android the background will be taller than on simulator or IOS. it looks it’s adding a pixel to each line i add in a text.

please confirm this on DEVICE not in simulator. tested on nexus 7 2013 and my blackberry z10 and ipad 4. only on nexus and blackberry gave me the added lines.

regards,

Carlos.

normal.jpg bug.jpg

btw, i already submitted to bug report.

This is not a bug. It’s the way Android and iOS generate text differently. Corona SDK uses native font rendering and its different on all the different platforms.

Rob

Rob, the bug is not in font rendering, but in counting the height of a display.newText. How do you insert a text bellow another block of text if you can’t rely on object.contentHeight?
Object.contentHeight must return that, the height of that object, and in display.newText it doesn’t and only on android.

Since I don’t know what your end design goals are and if you’re going to have more text than the 14 lines in your demo or not, but if this is data your fetching from a server of unknown size I would make a scrollView of a fixed height, set its background color and then insert the text into the scrollView. That way I know exactly how big my box will be instead of dealing a variable height box.

Also you may want to come up with a way to break the text into chunks. It’s too easy for large blocks of text to exceed MaxTextureSize and cause white blocks to show up instead of the actual text.

Rob

The text (description) is already inside of a fixed scrollview but i want to insert other data, like address, phone, email, etc. from other database fields in the same scrollview to look its from the same source. The description can have more than 30 lines but its limit is defined in the database so i will not have the maxtexturesize problem, even if it would…ive code for treat large chuncks of text. The problem is linear more lines in a display.newText more gap will have for the next text. I dont need the background color, i just put it in this demo code so you can see the problem. I want a chunck of text after a chunck of text and in android the gap from a block of text to the next happens. I can make a function to check if its android or ios device and from there resolve the problem myself. i think this is complicating what it appears a native function problem, but i guess i need to go this route. Thanks for the help anyway.

This is old. If you do a forum search if you will find several developers talking about that issue.

The work-around available for you are:

 

a ) Manually adjust the height value by using a ratio (@yosu suggested in this post). This only work if the text does not change dynamically.

 

b ) Implement a custom newText to show each line as a independent text object and get the total height by summing up the objects height)

Thanks Renato for your help. What i did was exactly what @yosu suggested. Still, i saved your code of custom newText if alls go bad with the first solution, thanks again.

btw, i already submitted to bug report.

This is not a bug. It’s the way Android and iOS generate text differently. Corona SDK uses native font rendering and its different on all the different platforms.

Rob

Rob, the bug is not in font rendering, but in counting the height of a display.newText. How do you insert a text bellow another block of text if you can’t rely on object.contentHeight?
Object.contentHeight must return that, the height of that object, and in display.newText it doesn’t and only on android.

Since I don’t know what your end design goals are and if you’re going to have more text than the 14 lines in your demo or not, but if this is data your fetching from a server of unknown size I would make a scrollView of a fixed height, set its background color and then insert the text into the scrollView. That way I know exactly how big my box will be instead of dealing a variable height box.

Also you may want to come up with a way to break the text into chunks. It’s too easy for large blocks of text to exceed MaxTextureSize and cause white blocks to show up instead of the actual text.

Rob

The text (description) is already inside of a fixed scrollview but i want to insert other data, like address, phone, email, etc. from other database fields in the same scrollview to look its from the same source. The description can have more than 30 lines but its limit is defined in the database so i will not have the maxtexturesize problem, even if it would…ive code for treat large chuncks of text. The problem is linear more lines in a display.newText more gap will have for the next text. I dont need the background color, i just put it in this demo code so you can see the problem. I want a chunck of text after a chunck of text and in android the gap from a block of text to the next happens. I can make a function to check if its android or ios device and from there resolve the problem myself. i think this is complicating what it appears a native function problem, but i guess i need to go this route. Thanks for the help anyway.

This is old. If you do a forum search if you will find several developers talking about that issue.

The work-around available for you are:

 

a ) Manually adjust the height value by using a ratio (@yosu suggested in this post). This only work if the text does not change dynamically.

 

b ) Implement a custom newText to show each line as a independent text object and get the total height by summing up the objects height)

Thanks Renato for your help. What i did was exactly what @yosu suggested. Still, i saved your code of custom newText if alls go bad with the first solution, thanks again.