Hi Brent and all,
My confession: My code sample had a bug of my own (see ** below)
My penance: Below is my work-around…
By way of explanation…
The skew/slanted text can show when simulating devices with screen sizes non-integer related to my iphone sized config (width = 320, height = 480).
Work-around Pseudo-code…
Create a tmp newText and record it’s width, then delete it.
Round up that width up to a multiple of 4. (taking display.contentScaleX into account)
Create the intended, skew immunized, near same sized text.
(My code bug **, recorded by Brent in bug report #22695 was that first tmpText had font BOLD , and the second not so.)
Executive summary: until bug fixed, I’m using the first lua snippet below: newTextSkewImmune(inString, x, y, font, charSize)
Exhastive demo: another, larger lua snippet showing problem and fix side by side.
A couple of notes:
-
Ive only tested for text lines shorter than screen width.
-
The work-around fix is really so trivial suggesting that actual under-lying bug fix should be flipped almost over-night.
(except that, of course, there will be issues I’ve not thought of)
[lua]
function newTextSkewImmune(inString, x, y, font, charSize)
local tmpText = display.newText(inString, 0,0, font, charSize)
local SLTW, SLTH = tmpText.width, tmpText.height
display.remove( tmpText )
tmpText = nil
local immuneX = (4*math.ceil(math.round(SLTW/display.contentScaleX)/4))*display.contentScaleX
local immuneY = (4*math.ceil(math.round(SLTH/display.contentScaleY)/4))*display.contentScaleY
local outText = display.newText(inString, x,y,immuneX, immuneY, font, charSize)
return outText
end
[/lua]
… and the full-on demo, side by side thing…
[lua]
display.setStatusBar( display.HiddenStatusBar )
sf = string.format
function makeMultN(x,N)
return ( N * math.ceil(x/N))
end
function appendArrayBToArrayA(arrayA,arrayB)
for i=1,#arrayB do
table.insert(arrayA,arrayB[i])
end
return arrayA
end
function newTextSkewImmune(inString, x, y, font, charSize)
local tmpText = display.newText(inString, 0,0, font, charSize)
local SLTW, SLTH = tmpText.width, tmpText.height
display.remove( tmpText )
tmpText = nil
local immuneX = (4*math.ceil(math.round(SLTW/display.contentScaleX)/4))*display.contentScaleX
local immuneY = (4*math.ceil(math.round(SLTH/display.contentScaleY)/4))*display.contentScaleY
local outText = display.newText(inString, x,y,immuneX, immuneY, font, charSize)
return outText
end
function mkMenuBubble(inString)
print("\n\n…in mkMenuBubble … inString is ", inString)
local charSize = 10
--SLT means Single Line Text
local tmpText = display.newText(inString, 0,0, native.systemFont, charSize)
local SLTW, SLTH, SLTA, SLTAR = tmpText.width, tmpText.height, tmpText.width * tmpText.height, tmpText.width / tmpText.height
print(sf(“SLTW, SLTH are %s ,%s”, SLTW, SLTH))
display.remove( tmpText )
tmpText = nil
local SLTWMultFour = makeMultN( SLTW , 4)
local SLTHMultFour = makeMultN( SLTH , 4)
print(sf("Rounding UP width and height up to multiples of 4… "))
print(sf(“Expect to make text of width and height\t\t%s\t%s”, SLTWMultFour, SLTHMultFour))
menuBubble = display.newText( inString ,0,0, SLTWMultFour, SLTHMultFour, native.systemFont, charSize )
menuBubble:setReferencePoint( display.TopLeftReferencePoint )
print(sf(“In fact width and height\t\t%s\t%s”, menuBubble.width, menuBubble.height))
return menuBubble
end
function mkMenuBubbleImmune(inString)
print("\n\n…in mkMenuBubbleImmune … inString is ", inString)
local font = native.systemFont
local charSize = 10
menuBubble = newTextSkewImmune(inString, x, y, font, charSize)
menuBubble:setReferencePoint( display.TopLeftReferencePoint )
print(sf(“In fact width and height\t\t%s\t%s”, menuBubble.width, menuBubble.height))
return menuBubble
end
function mkDictBubblesFromTabText(tableOfText)
local i = 1
for i=1,#tableOfText do
bubble = mkMenuBubble( tableOfText[i] )
bubbleImmune = mkMenuBubbleImmune( tableOfText[i] )
bubble.x, bubble.y = 80, i*20
bubbleImmune.x, bubbleImmune.y = 240, i*20
end
end
local testText0s = {“00005”, “000006”, “0000007”,“00000008”,“000000009”,“0000000010” }
local testText10s = {“00000____11”, “00000_____12”,“00000______13”,“00000_______14”,“00000________15”,“00000_________16”,“00000__________17”, “00000___________18” }
local testText = appendArrayBToArrayA(testText0s,testText10s)
local DeviceAspRatio = display.contentWidth/display.contentHeight
print(sf(“The device Aspect Ratio is %s”, DeviceAspRatio))
local contentSx = display.contentScaleX
local contentSy = display.contentScaleY
print(sf("\n\n\n … display.contentScaleX,Y are \n…%s\n…%s \n\n\n", contentSx, contentSy))
mkDictBubblesFromTabText(testText)
print(“Done”)
[/lua]