Computer Science Canada

Problem with Font.Draw, simple problem.

Author:  GlobeTrotter [ Mon Jan 31, 2005 6:07 pm ]
Post subject:  Problem with Font.Draw, simple problem.

code:

setscreen ("graphics:200,200")
var name : string := "1234567890"
var artistFont : int := Font.New ("Lucida Console:10x" + intstr (200 div length (name)) + "")
Font.Draw (name, 0, 0, artistFont, red)


In that code, why doesn't all of the text fit in? It simply does not make sense to me.

Author:  person [ Mon Jan 31, 2005 6:24 pm ]
Post subject: 

it has to do with the font u r using

Author:  GlobeTrotter [ Mon Jan 31, 2005 6:27 pm ]
Post subject: 

Actually, I don't think so. Its the same thing with Arial, and others. I intentionally tried a font that is uniform, since I thought this might have been a solution to the problem, but it wasn't

Author:  Cervantes [ Mon Jan 31, 2005 6:30 pm ]
Post subject: 

Perhaps because of the spacing between the numbers?
Perhaps Font.Width will be useful:
Turing:

setscreen ("graphics:200,200")
var name : string := "1234567890"
var font : int
for i : 1 .. 100
    font := Font.New ("Lucida Console:10x" + intstr (i))
    exit when Font.Width (name, font) >= maxx - 5 and Font.Width (name, font) <= maxx + 5
end for
Font.Draw (name, 0, 0, font, red)

It pains me to have to do that, but that's all I can think of at the moment. Eh
-Cervantes

Author:  person [ Mon Jan 31, 2005 6:36 pm ]
Post subject: 

Quote:
Actually, I don't think so. Its the same thing with Arial, and others. I intentionally tried a font that is uniform, since I thought this might have been a solution to the problem, but it wasn't


try these fonts, u should see a drastic difference:

Coronet
Edwardian Script ITC

if u dont...well i dont know ur problem cuz its different on my comp

Author:  basketball4ever [ Mon Jan 31, 2005 6:46 pm ]
Post subject: 

person wrote:
Quote:
Actually, I don't think so. Its the same thing with Arial, and others. I intentionally tried a font that is uniform, since I thought this might have been a solution to the problem, but it wasn't


try these fonts, u should see a drastic difference:

Coronet
Edwardian Script ITC

if u dont...well i dont know ur problem cuz its different on my comp



Mad don't listen x_X changing a font to make it look smaller is never the right way to do it. What's wrong is the size of font you're using currently and how wide each character is spaced apart in you're code. How to fix it: i don't know... but i know theres an error there because i can replace it with integers instead of variables to make it work

Author:  GlobeTrotter [ Mon Jan 31, 2005 6:48 pm ]
Post subject: 

Thanks Cervantes, that works. I made it a bit less hardcoded.

code:

var name : string := "Once upon a time there was a"
var font : int
var width : int := 200
for i : 1 .. 10
    font := Font.New ("Lucida Console:10x" + intstr (i))
    exit when Font.Width (name, font) >= width - (length (name) div 2) and Font.Width (name, font) <= width + (length (name) div 2)
end for
Font.Draw (name, 26, 0, font, red)


edit:

I found a way to make my original code work. I am unsure why the fix is necessary, but multiplying the width by 3/4 makes it right.

code:

setscreen ("graphics:200,200")
var name : string := "1234567890"
var artistFont : int := Font.New ("Lucida Console:10x" + intstr (round (3 / 4 * (200 div length (name)))) + "")
Font.Draw (name, 0, 0, artistFont, red)

Author:  person [ Mon Jan 31, 2005 7:17 pm ]
Post subject: 

correct me if im wrong cuz im not so sure about this...anyways...i have a feeling that it measures not in pixels, but in the width of a certain font size

Author:  basketball4ever [ Mon Jan 31, 2005 7:26 pm ]
Post subject: 

person wrote:
correct me if im wrong cuz im not so sure about this...anyways...i have a feeling that it measures not in pixels, but in the width of a certain font size


The width of a certain font size is measured in pixels. Thats how Font.Draw works. Thats why some fonts fit in his original coding, but not in others. However, you can fix the width of each font also. As shown by cervantes.


: