[20 Sep 2011] Yet Another Strange Bug

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
PEB
Posts: 576
Joined: Sun Feb 21, 2010 1:28 am

[20 Sep 2011] Yet Another Strange Bug

Post by PEB »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 20 Sep 2011 19:31:38 -0000

Please test the following code:

Code: Select all

SetFont(#SANS, 18, {Engine=#FONTENGINE_INBUILT})
TestText$="Test Text"
TestNum=9
Delta=-1
Function p_TestFunc()
	TestNum=TestNum+Delta
	If TestNum=5 Or TestNum=9 Then Delta=-Delta
	Length=TextWidth(LeftStr(TestText$, TestNum))
	DebugPrint(LeftStr(TestText$, TestNum), Length)
EndFunction
InstallEventHandler({OnMouseUp=p_TestFunc})
Repeat
	WaitEvent
Forever
For some strange reason, I get output like this:

Code: Select all

Test Tex 56   <---
Test Te 49   <---
Test T 42
Test  33
Test T 42
Test Te 51   <---
Test Tex 58   <---
Notice how the same text with the same built-in font reports different widths.

Any ideas?
User avatar
airsoftsoftwair
Posts: 5830
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[25 Sep 2011] Re: Yet Another Strange Bug

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Sun, 25 Sep 2011 22:11:09 +0200
Notice how the same text with the same built-in font reports different widths.

Any ideas?
Yes, this is a bug that I already noticed myself and fixed some two months ago. It is caused by Hollywood's glyph cache engine. To work around the bug, always call TextWidth() two times with the same string, i.e.

Code: Select all

Length=TextWidth(LeftStr(TestText$, TestNum))
Length=TextWidth(LeftStr(TestText$, TestNum))
The second call to TextWidth() will return correct metrics. Note that the TextExtent() function is also affected by this bug so you also have to call that function twice in order to get a really correct result.
Locked