Well, if I can come up with something that is of interest to the famous @roaminggamer, then that will be a very good day indeed! 
This may not be the world’s most elegant solution (it basically creates an invisible temporary newText, grabs the data we need, and then erases it), but I whipped up a quick module that I’m calling “textSpace.” It sets up a function textSpace.get() that you supply with the following:
- The string you’ll be plugging into your display.newText()
- The font you want to use
- The font size you want to use
- The desired width of your display.newText()
The function returns a table with two values: “numRows,” the number of rows in your desired display.newText() and “pixelHeight” which is the height of your desired display.newText() in pixels. Here is the module, which you should save as textSpace.lua and put in your project’s root directory:
local textSpace = {} ------------------------------------------------------------------------------------ -- DECLARE PLACEMENT VARIABLES (NOT ESSENTIAL, JUST MY OWN SHORTCUTS) ------------------------------------------------------------------------------------ local centerX = display.contentCenterX local centerY = display.contentCenterY local screenTop = display.screenOriginY local screenLeft = display.screenOriginX local screenBottom = display.screenOriginY+(display.contentHeight-(display.screenOriginY\*2)) local screenRight = display.screenOriginX+(display.contentWidth-(display.screenOriginX\*2)) local screenWidth = screenRight - screenLeft local screenHeight = screenBottom - screenTop ------------------------------------------------------------------------------------ -- GET ROW # & PIXEL HEIGHT FOR STRING WITH WIDTH ------------------------------------------------------------------------------------ function textSpace.get(string, font, fontSize, width) -- set width as screenWidth if not specified if string == nil or font == nil or fontSize == niln or width == nil then print("TEXTSPACE ERROR: You must supply four arguments when calling textSpace.get() - string, font, fontSize, & width") return true end -- calculate height of one row & height of whole text box local tempRow = display.newText(" ", 0, 0, font, fontSize) tempRow.isVisible = false local rowHeight = tempRow.height local tempText = display.newText(string, 0, 0, width, 0, font, fontSize) tempText.isVisible = false local pixelHeight = tempText.height local numRows = math.ceil(pixelHeight/rowHeight) display.remove(tempRow) tempRow = nil display.remove(tempText) tempText = nil -- return a table with the number of rows & pixel height return {["numRows"] = numRows, ["pixelHeight"] = pixelHeight} end return textSpace
And here is a sample main.lua that uses the module to successfully calculate the number of rows of a generic string of text. I tested this in the simulator using multiple device skins, and multiple strings, fonts, font sizes, etc, and it always returned the right data:
local textSpace = require("textSpace") ------------------------------------------------------------------------------------ -- DECLARE PLACEMENT VARIABLES (NOT ESSENTIAL, JUST MY OWN SHORTCUTS) ------------------------------------------------------------------------------------ local centerX = display.contentCenterX local centerY = display.contentCenterY local screenTop = display.screenOriginY local screenLeft = display.screenOriginX local screenBottom = display.screenOriginY+(display.contentHeight-(display.screenOriginY\*2)) local screenRight = display.screenOriginX+(display.contentWidth-(display.screenOriginX\*2)) local screenWidth = screenRight - screenLeft local screenHeight = screenBottom - screenTop ------------------------------------------------------------------------------------ -- DECLARE VARIABLES FOR OUR DISPLAY.NEWTEXT() ------------------------------------------------------------------------------------ local string = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." local font = native.systemFont local fontSize = 20 local width = screenWidth ------------------------------------------------------------------------------------ -- PRE-CALCULATE NUMBER OF ROWS & PIXEL HEIGHT ------------------------------------------------------------------------------------ local space = textSpace.get(string, font, fontSize, width) print("NUMBER OF ROWS: "..space.numRows) print("HEIGHT IN PIXELS: "..space.pixelHeight) ------------------------------------------------------------------------------------ -- CREATE AN ACTUAL DISPLAY.NEWTEXT() AND SEE IF WE GOT THE RIGHT NUMBER... ------------------------------------------------------------------------------------ test = display.newText(string, centerX, centerY, width, 0, font, fontSize) print("actual pixelHeight on-screen: "..test.height)
Hope this helps!