Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Problem with Font.Draw, simple problem.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
GlobeTrotter




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
person




PostPosted: Mon Jan 31, 2005 6:24 pm   Post subject: (No subject)

it has to do with the font u r using
GlobeTrotter




PostPosted: Mon Jan 31, 2005 6:27 pm   Post subject: (No 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
Cervantes




PostPosted: Mon Jan 31, 2005 6:30 pm   Post subject: (No 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
person




PostPosted: Mon Jan 31, 2005 6:36 pm   Post subject: (No 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
basketball4ever




PostPosted: Mon Jan 31, 2005 6:46 pm   Post subject: (No 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
GlobeTrotter




PostPosted: Mon Jan 31, 2005 6:48 pm   Post subject: (No 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)
person




PostPosted: Mon Jan 31, 2005 7:17 pm   Post subject: (No 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
Sponsor
Sponsor
Sponsor
sponsor
basketball4ever




PostPosted: Mon Jan 31, 2005 7:26 pm   Post subject: (No 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: