You could probably approximate it - for each character create a display object for it , measure its width then delete it (only need to do this once) and then use this to convert your space split string into a string with newlines at the appropriate points.
Well this seems like only way, but for some font like Chinese, breaking it will be a very challenging work, as corona dont treat each chinese character as a string character.
And not sure how is the rendering cost, because I am rendering a whole long list of paragraph that is about few thousand characters.
Lua and Corona probably arenât ideal for Chinese and similar fonts. I think you end up doing your own encoding a lot of the time - my BitmapFont library has options to change the encoding to UTF-8 so the non ASCII characters can be used but I donât think it is very well supported. In terms of the rendering cost, Bitmap font libraries will almost all be 1-1 character -> Corona image, so using the stock text is best at that sort of level. I would think the actual rendering would be fairly efficient, because itâs probably just directly calling an Android/iOS function or two which does that. Youâd probably just have to experiment with that - if you are thinking of running on a phone hardware scrounge an old discarded Android phone off someone who has upgraded and see how that copes with it. I also tend to have a really cheap (ÂŁ40 ish) android tablet as well for this sort of testing, stuff can work fine in the simulator but the cheap hardware canât manage it (though in my experience you have to really flog it !)
Lineheight is currently really bad in newText. Â Iâm surprised there arenât more posts about this.
The standard lineheight corona is using seems far to high and the inability to change it is Boooooooo.
I know we are dependent on the operating systemâs font rendering and on Android, it could vary from maker to maker.
Rob
Well, maybe. Â
Iâve been out of the  Corona loops for a little while⌠Iâm going back and updating apps I had last touched in 2012.
Back then, I was using the crawlspace libâs ânewParagraphâ function to handle multiline formatting. Â It included line height and alignment well better than the current ânewTextâ does.
It seems really âoddâ that a 3rd party lib 2 years ago was able to do it better than the current built in system. Â Give a try on a multi-line with something like AmericanTypewriter at size 18. Â Itâs not even close to useful without the ability to change the line height.
Of course, Â I do partially blame myself for not looking to see if there was just an updated crawlspace lib before re-writing a whole bunch of code to work with the new newText. Â Still canât help be a bit disappointed that after all this time, writing text with Corona is so painful.
Well ok, I feel a little better that it has NOT been updated.
But check the newParagraph setup there.  I suppose I could just got back re-wrap a wrapless (no-width) newText call ⌠But seriously, at this age in Corona, it seems we shouldnât have to do that just to get lineheight control.
I can ask the Engineers to look into this, but they are going to want a bug report. The bug report needs to have any assets needed to run it, and a config.lua and build.settings in a .zip file.
Rob
⌠Sure â  Or anyone could save the trouble of that just drop this at the top of any ole main.lua they have sitting around real quick for an example â or see the screenshot attached (see bottom of post) â or try just actually using the language for a purpose other than a game.  ;-)
local options = { text = "This is a long line of text that shows how much line height is used. On small screens, space is a premium commodity and this is a waste.", width = display.contentWidth\*.85, font="AmericanTypewriter-Bold", fontSize = 20, align = "center" } local tmpText = display.newText (options) tmpText.x = display.contentWidth/2; tmpText.y = display.contentHeight/2 - 100; local options = { text = "Meanwhile, the line height on this font is not so bad... but given screenspace, there is STILL room that a developer might want to salvage.", width = display.contentWidth\*.85, font=native.systemFont, fontSize = 24, align = "center" } local tmpText = display.newText (options) tmpText.x = display.contentWidth/2; tmpText.y = display.contentHeight/2 + 120; if (1==1) then return true end;
Also, note that when you go to add code to a post here in the forum, Lua is oddly not an options in the menu. Â Granted, thatâs not needed â but given that this is a Lua oriented forum.
⌠And then hereâs a quick real-world example of where the space is causing problems in our âCharacter Promptsâ appâŚ
This is just one example on one screen of one app. Â But you can see that we donât need that kind of line spacing for any of these fields. Â They would be much better off scrunched together a little. Â It looks very cluttered because trait and hobby, in particular are spread so much. Â Favorite saying also takes up much more room than it needs to via the newText() line height.
Character Prompts is currently in the store using the âold wayâ and crawlspaceâŚ
https://itunes.apple.com/us/app/character-prompts/id493346374
If you want Engineering to look at this, there has to be a trackable entry in the bug database. Engineering does not use Forums as means to allocate and track their work.Â
That said, I donât see that much of an issue above. Fonts, in particular once you get away from the main font foundries and heavily tested fonts and into free fonts, you will find that there are tons of âmetricâ problems with them. These metric issues manifest themselves in things like the characters sitting too high in their box, being too short for the space asked for etc.
I donât know what we can do since we hand the font to the OS and get an image back and thereâs not much in between. I donât know if we can specify a line height or not when we ask the OS to render the text, but that is the most likely scenario. We canât analyze every font.
Rob
I wouldnât expect Corona to analyze every font.
Iâd just like the ability to set the line height myself if I donât like the default.
Itâs really one of those basic stylization things that most designers have an interest in tweaking.
I also posted a screenshot above from our real world app that it does cause a problem with. Â I will have to use a different font or use/update the newParagraph function from the crawlspace lib. Â My point still being that line height control is a basic thing that folks shouldnât have to write wrappers for in 2014.
Hello
and yes, lineHeight and letterSpacing is badly needed!
I havenât read all posts here, but as I produced some fonts myself, I would like to add:
lineHeight might not be a big thing to achieve. Every font delivers its geometry which is read and used by the script. display.newText() seems to read the basic fontHeight of a font, using this as a parameter for lineHeight. This is why the lines in rendered texts are so narrow, it is like lineHeight 1.0 in other applications. Itâs not best readable.
It would be a great if the Corona Engineering could at least add this feature: with units of em = multiples of the fontSize or in Corona pixel.Â
If the Engineering need some more detail information about font techniques, please let me know, maybe I can help.
I just declined a feature request on this since it had been nearly two years with a total of two votes on it. Feel free to create a new feedback item for it, though it would be a better use of your votes to vote on some of the other display.newText() based feature requests.
http://feedback.coronalabs.com
Rob
Hi Rob,
there are aome different feature requests about text and aligning / line height / spacing / manipulating. I searched for âtextâ as a keyword.
The sum of all votes is 380.
Maybe there is a chance to combine these feature requests as they address mostly the same topic, with a little different details.
164 votes:
more control and choices for text objects
120 votes for:
display.newText() advanced options / justification
51Â votes for:
Stroke to text
45Â votes for:
Manipulate text size, style, font, and color like HTML
Kind regards from Berlin,
Simon
Yes, we can combine those into a mega request. Itâs a lot of votes. But text is a complex thing that can pull our engineers down a rabbit hole that will. I suspect that Perk will have some ideas on what things we should work on next, but weâve not had time to have those conversations yet.Â
Rob
Hi Rob,Â
this is good news for all who love good typography in apps
Many Corona developers would be very happy!
My suggestion would be:
-
line height and letter spacing
-
manipulation of single or several strings inside of a text: in size, position, color and even font style, making text like âCO2â possible
-
other text manipulation like stroke or outlined letters
If the default line height is left at 1.0, there might be no change to existing apps.
Simon
Personally I donât think its either âgoodâ or ânewsâ. Itâs purely administrative information. I can combine the various requests into one. I havenât yet, because I need to make sure all of the various items are represented in the mega-request. Also Iâm concerned the bigger the task, the harder it will to get the request done.
Please do not read my previous comment as any commitment to any progress on it.
Rob
Adjusting line height and character spacing is a critical feature!
My manager has asked me to suggest a 2D platform for mobile development; and I am having to pass on Corona because it wonât be able to deliver even the minimum basic requirements that the design team expects. I am personally a huge fan of Corona, but with modern app development the in-ability to do even the most basic text formatting is crippling.
Please fix this!!!