newText returning wrong values on multiline texts

This problem happens on Android devices only.

For each line on display.newText, a extra height is being added, making the text height be incorrect specially on large texts ( > 10 lines).

Bug case #36337

Screenshot of the problem (in the image I created 3 display.newText with different lengths and I added 3 lines marking the top, center, bottom of each newText)

screenshot-GalaxyS3_Android43.png

It has been there for sometime. I did complain and file something many months ago. The length get’s more obvious if the text is longer.

Anyway, after much testing, i found that this offset works nicely (only  for Android). I use the ratio below.

TEXT\_FIELD\_TO\_ACTUAL\_RATIO = (8/10)

Received the following reply from Corona today:

Thanks for reporting the bug. I talked to our engineer and he says this because of the value returned by Android OS and we can’t do anything more to return a more accurate value. The value returned in the text object is the bitmap size Android uses to display the text. What you’re trying to do is not supported cross-platform.

It has been there for sometime. I did complain and file something many months ago. The length get’s more obvious if the text is longer.

Anyway, after much testing, i found that this offset works nicely (only  for Android). I use the ratio below.

TEXT\_FIELD\_TO\_ACTUAL\_RATIO = (8/10)

Received the following reply from Corona today:

Thanks for reporting the bug. I talked to our engineer and he says this because of the value returned by Android OS and we can’t do anything more to return a more accurate value. The value returned in the text object is the bitmap size Android uses to display the text. What you’re trying to do is not supported cross-platform.

I’ve found the same issue, Android size reported is incorrect. However, I’m limited in terms of devices. My analysis is that the size is 18.75 bigger than simulator or IOS.

Anyone confirm those figures on their device? Mine ae HTC running 2.3 and rooted Kindle fire (1st gen) running 4.0

I’ve found the same issue, Android size reported is incorrect. However, I’m limited in terms of devices. My analysis is that the size is 18.75 bigger than simulator or IOS.

Anyone confirm those figures on their device? Mine ae HTC running 2.3 and rooted Kindle fire (1st gen) running 4.0

Just want to know if there is any workaround after nearly 1 year.

Is there any method to get / calculate the better value of height of the multi-line text?

Depends on the devices, some of the value are just fit, while some are too large which makes too much space under the text.

It is difficult to develop since I cannot find a method to trim space.

Does it have some relationship between screen pixel or something that at least I can calculate by myself?

No update from what I know. I made some replies to Corona after their feedback and basically they don’t consider that incorrect height on Android to be a bug… very disappointed.

Sometimes their answers made me disappointed when I asked in this forum.

Even they don’t think it is a bug, something should be done to make the situation better.
Since my apps contains Chinese character, I cannot use “bitmap font”.

And such space in multiline text makes my app display so weird.

The work-around available for you are:

a ) Manually adjust the height value by using a ratio (@yosu suggested). 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)

Both are not work for me.

I have 3 devices for testing.

For a ), each devices have different ratio of space, which I cannot simply use ratio to trim the space

For b ), it seems not applicable since I have a relatively large paragraph to display. It will need a heavy calculation to make the app hang a while when I create the text.

a ) I believe that should work depending on the content scale that you are using (it worked for me).

b ) I also thought that but then I implemented a custom display text that do that and it works very well with a huge amount of text. In addition, Corona recommends that when you have a huge text to split it in several newText objects because newText objects are rendered as images and so you are capped by the texture limit. (https://coronalabs.com/blog/2014/06/17/tutorial-working-with-large-blocks-of-text/)

a ) I’m not sure if the display content setting is ok

width = 1080,

height = 1080*heightRatio,   – where heightRatio = display.pixelHeight/display.pixelWidth

In my test, not all the device can fit for one scale even I use custom font. I tried to tune a value to use in all device, but the range is too large, which makes me cannot just use scaling.

There are two devices, Redmi and Samsung S3, have the same screen size, but the corresponding suitable ratio should be 0.73 and 0.63 respectively.

b ) I have already split the paragraph by /r/n. But if the text is split by line, we need to create and destroy the text objects many time for every row. So I thought it is not applicable.

However, the method b is seems the ONLY method that I can try. I’ll see if it is work for me.

Thanks for your advice.

If you want, take a look on my code. In my case a split word by word because I wanted to control the word spacing and line spacing.

Just do a 

require "custom-display"

and call

local myText = display.newText2(optionsTable)

where optionsTable is the same that you provide to Corona newText.

You can get my code at: https://www.dropbox.com/s/hswbx2yxgc538nu/custom-display.lua?dl=0

Thanks for your great help ;) 
Your source code helps me to have a better direction to work on this. :slight_smile:

Just want to know if there is any workaround after nearly 1 year.

Is there any method to get / calculate the better value of height of the multi-line text?

Depends on the devices, some of the value are just fit, while some are too large which makes too much space under the text.

It is difficult to develop since I cannot find a method to trim space.

Does it have some relationship between screen pixel or something that at least I can calculate by myself?

No update from what I know. I made some replies to Corona after their feedback and basically they don’t consider that incorrect height on Android to be a bug… very disappointed.

Sometimes their answers made me disappointed when I asked in this forum.

Even they don’t think it is a bug, something should be done to make the situation better.
Since my apps contains Chinese character, I cannot use “bitmap font”.

And such space in multiline text makes my app display so weird.

The work-around available for you are:

a ) Manually adjust the height value by using a ratio (@yosu suggested). 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)