OK T, I think I got it. I only have an iPad retina and a motorola atrix to test on, but the font size looks identical (scaled I mean, irl the ipad font is much larger because it’s scaled up like my other content).
But the font really does look identical on these devices. I have plugged in screen height numbers for the other iOS devices which I think are correct, but I’ll have to test on the devices.
For droid, it retrieves the screen height as in your post above, and uses that to do the calc. The code also compensates for corona chopping off the top and bottom of the screen to map the virtual content into. Only seen that code execute on my droid atrix, and it seems to be right, but I’ll need to try it on some other devices to make sure all my add/subtract stuff is correct. Font size looks perfect (relative to my other content) on my atrix though (identical to how it appears on my retina ipad).
[lua]
print(" – calcFontSize()")
print("-----------------------" )
local sysType = system.getInfo(“architectureInfo”)
print(" – sysType == “, sysType)
print(” – display.contentScaleY == “, display.contentScaleY )
print(” – display.screenOriginY == “, display.screenOriginY )
inputFontSize = targetFontSize / display.contentScaleY – old method is fallback (ends up being sim setting)
if( utils.isAndroid == true ) then – try and get the real width / height and deal with it
print(” – -- Android font size calc…")
local missingInches = display.screenOriginY * -2 – account for both top and bottom area (x2), and change the sign sign since originY is always negative, if it exists…
missingInches = missingInches / 320 – 320 is 1 inch, in my 640x960 virual content space (960 == 3 inches for my app, designed for a standard iphone 4 display)
– different contentScale sizes will use a different virtual pixel / inch value (eg, 320x480 virtual content = missingInches / 160)
print(" – missing inches == “, missingInches)
local fontScale = 1
local heightIn = system.getInfo( “androidDisplayHeightInInches” )
local widthIn = system.getInfo( “androidDisplayWidthInInches” )
print(” – original height == “, heightIn)
heightIn = heightIn - missingInches
--Make sure its not nil… e.g. the simulator will return nil, perhaps some bad devices will too…
if heightIn ~= nil then
– heightIn is height of actual droid app is running on
fontScale = heightIn / 3.0 – 3.0 is actual iPhone 3gs /4 /4s height
print(” – fontsize set on actual droid screen inch height")
print(" – widthIn = “, widthIn)
print(” – heightIn = “, heightIn)
else
fontScale = 4/3 --Default to a 4 inch diagonal (iphone is 3.0)
print(” – fontsize set to 4 inch phone size")
end
print(" fontScale == “, fontScale)
inputFontSize = targetFontSize*fontScale
else – else is iOS
print(” – -- iOS font size calc…")
local fontScale = 1
local heightIn = 3 – default to stnadard iPhone size
local missingInches = display.screenOriginY * -2 – account for both top and bottom area (x2), and change the sign sign originY is negative, if it exists…
missingInches = missingInches / 320 – 320 is 1 inch, in my 640x960 virual content space (960 == 3 inches for my app, designed for a standard iphone 4 display)
– different contentScale sizes will use a different virtual pixel / inch value (eg, 320x480 virtual content = missingInches / 160)
print(" – missing inches == ", missingInches)
–
– Since there is no corona facility to get the screen height of the device on iOS, we’ll determine it ourselves.
–
if( sysType == “iPhone2,1” ) then – 3GS
heightIn = 3.0 - missingInches – original iPhone size
print(" – iPhone 3GS detected")
elseif( string.match(sysType, “iPhone3”) or string.match(sysType, “iPhone4”) ) then – iPhone 4, 4S
heightIn = 3.0 - missingInches – Same size as the old 3gs- better resolution, but same size
print(" – iPhone 4 detected")
elseif( string.match(sysType, “iPhone5”) ) then – iPhone 5
heightIn = 4.0 - missingInches – Should go back to 3, after missing inches chopped off by corona are deducted.
print(" – iPhone 5 detected") – This phones screen is taller, a little… Corona will end up chopping it off though
elseif sysType == “iPad2,5” or sysType == “iPad2,6” or sysType == “iPad2,7” or sysType == “iPad2,8” then – 2,8 is unknown, just a guess at next mini #
heightIn = 6.25 - missingInches – mini
print(" – iPad mini detected") – A good amount taller. Need a much bigger point size for this device, for the input fonts to look scaled right
elseif( string.match(sysType, “iPad”) ) then – standard iPad
heightIn = 7.75 - missingInches – iPad
print(" – iPad detected") – MUCH taller screen, really gonna need to scale fonts up in point size for this bad boy (or they will look less than half size for the field)
else
print(" – unrecognized iOS device, using default 3.5 inches tall") – iPods will fall to here, they are 3.5 anyways…
if( missingInches == 0 ) then
– iPod falls through to here (and it is 3 inches tall, and any missing inches accounted for in a tall version, so that works for now)
heightIn = 3.0 - missingInches – I would hope this is typical, zero extra on an unknown ios device
else
heightIn = 4.0 - missingInches – otherwise, we’ll take a flying guess that the unknown device is bigger than a tiny breadbox, and smaller than a car. (4 inches tall, iphone 5 format)
end
end
fontScale = heightIn / 3.0 – 3.0 inches is actual iPhone 4 height (that my content is based on)
inputFontSize = targetFontSize*fontScale
end
print(" – final fontsize == “, inputFontSize)
print(”-----------------------" )
return inputFontSize
[/lua]
So the big question to me is, are there many droid devices actually reporting the *wrong* height. If so, then this might not work out. If, however, they are returning the right height (but it was being used as if it were diagonal height, or some other mistake), then this should work mint.