Re: [pygame] How the get a font size

2009-01-14 Thread Luca
On Tue, Jan 13, 2009 at 6:07 PM, Brian Fisher br...@hamsterrepublic.com wrote:
 Well in that case, it seems that knowing the size value passed to the
 constructor is only half of what you need to make a font at twice the size
 of the original.

You are not missing anything Brian, if facts you are right... I can do
anything with the size info alone...

I think that is not so good not beeing able to take those infos from
the Font object, but now I see that is not so important!

I will followe that path of the wrapper FakeFont class!

Thank you all!

-- 
-- luca


Re: [pygame] How the get a font size

2009-01-13 Thread Luca
On Tue, Jan 13, 2009 at 8:37 AM, Noah Kantrowitz n...@coderanger.net wrote:
 You clearly don't understand how C classes work. Please consult the Python
 documentation.

Thanks you all guys. I perfectly understand the problem, however
adding a new attribute isn't what I was looking for.

The Front wrapper class seems the best way I can use.

For who asked: I wanted to write down an utility that given a Font can
enable a raise effect that major the size of 100%, 200%, ...

PS: you think that adding at C level a new font_size, readonly
attribute can be a valid request for future Pygame release? I think
that this can hovewer be useful...

-- 
-- luca


Re: [pygame] How the get a font size

2009-01-13 Thread Lenard Lindstrom

James Paige wrote:

On Mon, Jan 12, 2009 at 04:54:38PM -0800, Lenard Lindstrom wrote:
  

Hi,

James Paige wrote:


[snip]

f.pointsize = 12
   


Traceback (most recent call last):
 File stdin, line 1, in module
AttributeError: 'pygame.font.Font' object has no attribute 'pointsize'

I'm guessing that since pygame.font.Font is impelmented in C, it doesn't 
allow new members to be added as it would if it was implemented in 
python (Correct me if I am wrong)


 
  
You're right. Font instances lack attribute dictionaries. It was a 
design decision, or omission, and not a restriction of Font being 
implemented in C.





Ah, interesting. I stand corrected.

Why was the attribute dictionary left out? What is the advantage? Is it 
a performance thing?


  
Basically to save memory. It is also easy to overlook when coding a new 
extension type.


--
Lenard Lindstrom
le...@telus.net



Re: [pygame] How the get a font size

2009-01-13 Thread Noah Kantrowitz

On Jan 13, 2009, at 12:09 AM, Luca wrote:

On Tue, Jan 13, 2009 at 8:37 AM, Noah Kantrowitz  
n...@coderanger.net wrote:
You clearly don't understand how C classes work. Please consult the  
Python

documentation.


Thanks you all guys. I perfectly understand the problem, however
adding a new attribute isn't what I was looking for.

The Front wrapper class seems the best way I can use.

For who asked: I wanted to write down an utility that given a Font can
enable a raise effect that major the size of 100%, 200%, ...

PS: you think that adding at C level a new font_size, readonly
attribute can be a valid request for future Pygame release? I think
that this can hovewer be useful...


As was mentioned, using the size you pass to the font initially is  
probably the wrong thing to do. The .size() function gives you the  
actual pixel size of the font.


--Noah


Re: [pygame] How the get a font size

2009-01-13 Thread James Paige
On Tue, Jan 13, 2009 at 12:12:54AM -0800, Lenard Lindstrom wrote:
 James Paige wrote:
 On Mon, Jan 12, 2009 at 04:54:38PM -0800, Lenard Lindstrom wrote:
   
 Hi,
 
 James Paige wrote:
 
 [snip]
 f.pointsize = 12

 
 Traceback (most recent call last):
  File stdin, line 1, in module
 AttributeError: 'pygame.font.Font' object has no attribute 'pointsize'
 
 I'm guessing that since pygame.font.Font is impelmented in C, it doesn't 
 allow new members to be added as it would if it was implemented in 
 python (Correct me if I am wrong)
 
  
   
 You're right. Font instances lack attribute dictionaries. It was a 
 design decision, or omission, and not a restriction of Font being 
 implemented in C.
 
 
 
 Ah, interesting. I stand corrected.
 
 Why was the attribute dictionary left out? What is the advantage? Is it 
 a performance thing?
 
   
 Basically to save memory. It is also easy to overlook when coding a new 
 extension type.

I see. Thanks for the clarification :)

---
James Paige


Re: [pygame] How the get a font size

2009-01-12 Thread Luca
On Sun, Jan 11, 2009 at 10:36 PM, Noah Kantrowitz n...@coderanger.net wrote:

 As far as I know, there's no way to get the size of the font that way.
  What I do is name the font names in an intuitive way:
 Font12 = pygame.font.Font(, 12)
 Font18 = pygame.font.Font(, 18)
 Font36 = pygame.font.Font(, 36)

Thanks all, but in this way is impossible to get the size on an unknow
font? I'm making a library for developer that need to know what is the
font size that the developer can have choosen...

-- 
-- luca


Re: [pygame] How the get a font size

2009-01-12 Thread Ian Mallett
At some point, you're going to have to have a pygame.font.{Sys|}Font() call,
and in that call, you're going to have to specify a size.  The developer
will either have to specify a size to load (so the developer already knows)
or load every size.  If the latter is the case and choosing an arbitrary
size is then a problem, you can make your own font class with the relevant
attribute for each font size.


Re: [pygame] How the get a font size

2009-01-12 Thread Brian Fisher
On Mon, Jan 12, 2009 at 12:02 AM, Luca luca...@gmail.com wrote:

 Thanks all, but in this way is impossible to get the size on an unknow
 font? I'm making a library for developer that need to know what is the
 font size that the developer can have choosen...

 The problem is that SDL does not currently expose the size property in a
reliable way, so getting the size argument that was used to create the
font object is not really practical.

However, pygame.font does expose a number of metrics (ascent, descent, max
height, line spacing and sizing info and advance for individual characters)
about the rendered font that can be used to figure out how to work with a
font in a large number of cases, regardless of the point size argument used
in the font's constructor. In fact, the point size of the font may not
actually relate to anything about the font's rendered pixel size (that's
really up to the font designed, who's allowed to design outside the box in
a number of ways), so the point size itself can be misleading in determining
positioning choices depending on the individual ttf used.

So Luca, what are you trying to do with the font object passed in, in your
library? In what way do you expect the font point size passed into the
constructor to the Font object to help you with that task?


Re: [pygame] How the get a font size

2009-01-12 Thread Jake b
Create a basic Font() wrapper. When you create the font, save the size.
On Mon, Jan 12, 2009 at 2:02 AM, Luca luca...@gmail.com wrote:

 On Sun, Jan 11, 2009 at 10:36 PM, Noah Kantrowitz n...@coderanger.net
 wrote:

  As far as I know, there's no way to get the size of the font that way.
   What I do is name the font names in an intuitive way:
  Font12 = pygame.font.Font(, 12)
  Font18 = pygame.font.Font(, 18)
  Font36 = pygame.font.Font(, 36)

 Thanks all, but in this way is impossible to get the size on an unknow
 font? I'm making a library for developer that need to know what is the
 font size that the developer can have choosen...

 --
 -- luca




-- 
Jake


Re: [pygame] How the get a font size

2009-01-12 Thread James Paige
Seems to me like this should work:

class SizeFont(pygame.font.Font):

  def __init__(self, filename, size):
  pygame.font.Font.__init__(self, filename, size)
  self.size = size

---
James Paige

On Mon, Jan 12, 2009 at 04:07:11PM -0600, Jake b wrote:
Create a basic Font() wrapper. When you create the font, save the size.
On Mon, Jan 12, 2009 at 2:02 AM, Luca luca...@gmail.com wrote:
 
  On Sun, Jan 11, 2009 at 10:36 PM, Noah Kantrowitz n...@coderanger.net
  wrote:
 
   As far as I know, there's no way to get the size of the font that
  way.
What I do is name the font names in an intuitive way:
   Font12 = pygame.font.Font(, 12)
   Font18 = pygame.font.Font(, 18)
   Font36 = pygame.font.Font(, 36)
 
  Thanks all, but in this way is impossible to get the size on an unknow
  font? I'm making a library for developer that need to know what is the
  font size that the developer can have choosen...
 
  --
  -- luca
 
--
Jake


Re: [pygame] How the get a font size

2009-01-12 Thread Thiago Chaves
You can also just violate the object by giving it an extra attribute:

f = pygame.font.Font(filename, size)
f.new_attribute = size

I'm pretty sure any OO enthusiast would applaud this method. There is
certainly nothing bad that can be said about my method. No sir. =D

-Thiago

On Tue, Jan 13, 2009 at 12:48 AM, James Paige b...@hamsterrepublic.com wrote:
 Seems to me like this should work:

 class SizeFont(pygame.font.Font):

  def __init__(self, filename, size):
  pygame.font.Font.__init__(self, filename, size)
  self.size = size

 ---
 James Paige

 On Mon, Jan 12, 2009 at 04:07:11PM -0600, Jake b wrote:
Create a basic Font() wrapper. When you create the font, save the size.
On Mon, Jan 12, 2009 at 2:02 AM, Luca luca...@gmail.com wrote:

  On Sun, Jan 11, 2009 at 10:36 PM, Noah Kantrowitz n...@coderanger.net
  wrote:

   As far as I know, there's no way to get the size of the font that
  way.
What I do is name the font names in an intuitive way:
   Font12 = pygame.font.Font(, 12)
   Font18 = pygame.font.Font(, 18)
   Font36 = pygame.font.Font(, 36)

  Thanks all, but in this way is impossible to get the size on an unknow
  font? I'm making a library for developer that need to know what is the
  font size that the developer can have choosen...

  --
  -- luca

--
Jake



Re: [pygame] How the get a font size

2009-01-12 Thread James Paige
The only bad thing I can say about it is that it simply doesn't work :(

 f = pygame.font.Font(None, 12)
 f.size = 12
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'pygame.font.Font' object attribute 'size' is read-only

And that is not just because Font already has a method named .size()

 f.pointsize = 12
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'pygame.font.Font' object has no attribute 'pointsize'

I'm guessing that since pygame.font.Font is impelmented in C, it doesn't 
allow new members to be added as it would if it was implemented in 
python (Correct me if I am wrong)

---
James Paige

On Tue, Jan 13, 2009 at 01:54:30AM +0200, Thiago Chaves wrote:
 You can also just violate the object by giving it an extra attribute:
 
 f = pygame.font.Font(filename, size)
 f.new_attribute = size
 
 I'm pretty sure any OO enthusiast would applaud this method. There is
 certainly nothing bad that can be said about my method. No sir. =D
 
 -Thiago
 
 On Tue, Jan 13, 2009 at 12:48 AM, James Paige b...@hamsterrepublic.com 
 wrote:
  Seems to me like this should work:
 
  class SizeFont(pygame.font.Font):
 
   def __init__(self, filename, size):
   pygame.font.Font.__init__(self, filename, size)
   self.size = size
 
  ---
  James Paige
 
  On Mon, Jan 12, 2009 at 04:07:11PM -0600, Jake b wrote:
 Create a basic Font() wrapper. When you create the font, save the size.
 On Mon, Jan 12, 2009 at 2:02 AM, Luca luca...@gmail.com wrote:
 
   On Sun, Jan 11, 2009 at 10:36 PM, Noah Kantrowitz 
  n...@coderanger.net
   wrote:
 
As far as I know, there's no way to get the size of the font that
   way.
 What I do is name the font names in an intuitive way:
Font12 = pygame.font.Font(, 12)
Font18 = pygame.font.Font(, 18)
Font36 = pygame.font.Font(, 36)
 
   Thanks all, but in this way is impossible to get the size on an unknow
   font? I'm making a library for developer that need to know what is the
   font size that the developer can have choosen...
 
   --
   -- luca
 
 --
 Jake
 
 
 


Re: [pygame] How the get a font size

2009-01-12 Thread Thiago Chaves
I'm also sure that  not working is hardly a serious issue. =P

-Thiago

On Tue, Jan 13, 2009 at 2:04 AM, James Paige b...@hamsterrepublic.com wrote:
 The only bad thing I can say about it is that it simply doesn't work :(

 f = pygame.font.Font(None, 12)
 f.size = 12
 Traceback (most recent call last):
  File stdin, line 1, in module
 AttributeError: 'pygame.font.Font' object attribute 'size' is read-only

 And that is not just because Font already has a method named .size()

 f.pointsize = 12
 Traceback (most recent call last):
  File stdin, line 1, in module
 AttributeError: 'pygame.font.Font' object has no attribute 'pointsize'

 I'm guessing that since pygame.font.Font is impelmented in C, it doesn't
 allow new members to be added as it would if it was implemented in
 python (Correct me if I am wrong)

 ---
 James Paige

 On Tue, Jan 13, 2009 at 01:54:30AM +0200, Thiago Chaves wrote:
 You can also just violate the object by giving it an extra attribute:

 f = pygame.font.Font(filename, size)
 f.new_attribute = size

 I'm pretty sure any OO enthusiast would applaud this method. There is
 certainly nothing bad that can be said about my method. No sir. =D

 -Thiago

 On Tue, Jan 13, 2009 at 12:48 AM, James Paige b...@hamsterrepublic.com 
 wrote:
  Seems to me like this should work:
 
  class SizeFont(pygame.font.Font):
 
   def __init__(self, filename, size):
   pygame.font.Font.__init__(self, filename, size)
   self.size = size
 
  ---
  James Paige
 
  On Mon, Jan 12, 2009 at 04:07:11PM -0600, Jake b wrote:
 Create a basic Font() wrapper. When you create the font, save the size.
 On Mon, Jan 12, 2009 at 2:02 AM, Luca luca...@gmail.com wrote:
 
   On Sun, Jan 11, 2009 at 10:36 PM, Noah Kantrowitz 
  n...@coderanger.net
   wrote:
 
As far as I know, there's no way to get the size of the font that
   way.
 What I do is name the font names in an intuitive way:
Font12 = pygame.font.Font(, 12)
Font18 = pygame.font.Font(, 18)
Font36 = pygame.font.Font(, 36)
 
   Thanks all, but in this way is impossible to get the size on an 
  unknow
   font? I'm making a library for developer that need to know what is 
  the
   font size that the developer can have choosen...
 
   --
   -- luca
 
 --
 Jake
 





Re: [pygame] How the get a font size

2009-01-12 Thread Lenard Lindstrom

Hi,

James Paige wrote:

The only bad thing I can say about it is that it simply doesn't work :(

  

f = pygame.font.Font(None, 12)
f.size = 12


Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'pygame.font.Font' object attribute 'size' is read-only

And that is not just because Font already has a method named .size()

  

f.pointsize = 12


Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'pygame.font.Font' object has no attribute 'pointsize'

I'm guessing that since pygame.font.Font is impelmented in C, it doesn't 
allow new members to be added as it would if it was implemented in 
python (Correct me if I am wrong)


  
You're right. Font instances lack attribute dictionaries. It was a 
design decision, or omission, and not a restriction of Font being 
implemented in C.



---
James Paige

On Tue, Jan 13, 2009 at 01:54:30AM +0200, Thiago Chaves wrote:
  

You can also just violate the object by giving it an extra attribute:

f = pygame.font.Font(filename, size)
f.new_attribute = size





--
Lenard Lindstrom
le...@telus.net



Re: [pygame] How the get a font size

2009-01-12 Thread James Paige
On Mon, Jan 12, 2009 at 04:54:38PM -0800, Lenard Lindstrom wrote:
 Hi,
 
 James Paige wrote:
 The only bad thing I can say about it is that it simply doesn't work :(
 
   
 f = pygame.font.Font(None, 12)
 f.size = 12
 
 Traceback (most recent call last):
   File stdin, line 1, in module
 AttributeError: 'pygame.font.Font' object attribute 'size' is read-only
 
 And that is not just because Font already has a method named .size()
 
   
 f.pointsize = 12
 
 Traceback (most recent call last):
   File stdin, line 1, in module
 AttributeError: 'pygame.font.Font' object has no attribute 'pointsize'
 
 I'm guessing that since pygame.font.Font is impelmented in C, it doesn't 
 allow new members to be added as it would if it was implemented in 
 python (Correct me if I am wrong)
 
   
 You're right. Font instances lack attribute dictionaries. It was a 
 design decision, or omission, and not a restriction of Font being 
 implemented in C.
 

Ah, interesting. I stand corrected.

Why was the attribute dictionary left out? What is the advantage? Is it 
a performance thing?

---
James Paige


Re: [pygame] How the get a font size

2009-01-12 Thread Noah Kantrowitz


On Jan 12, 2009, at 8:46 PM, James Paige wrote:


On Mon, Jan 12, 2009 at 04:54:38PM -0800, Lenard Lindstrom wrote:

Hi,

James Paige wrote:
The only bad thing I can say about it is that it simply doesn't  
work :(




f = pygame.font.Font(None, 12)
f.size = 12


Traceback (most recent call last):
File stdin, line 1, in module
AttributeError: 'pygame.font.Font' object attribute 'size' is read- 
only


And that is not just because Font already has a method named .size()



f.pointsize = 12


Traceback (most recent call last):
File stdin, line 1, in module
AttributeError: 'pygame.font.Font' object has no attribute  
'pointsize'


I'm guessing that since pygame.font.Font is impelmented in C, it  
doesn't

allow new members to be added as it would if it was implemented in
python (Correct me if I am wrong)



You're right. Font instances lack attribute dictionaries. It was a
design decision, or omission, and not a restriction of Font being
implemented in C.



Ah, interesting. I stand corrected.

Why was the attribute dictionary left out? What is the advantage? Is  
it

a performance thing?


You clearly don't understand how C classes work. Please consult the  
Python documentation.


--Noah


[pygame] How the get a font size

2009-01-11 Thread Luca
Hi all.

I'm looking at the Font class API's, but I found no way to get the
size of a given font.
When I create a new font like

f1 = pygame.font.Font(, 12)

how can I get the size value (12) after the creation?

f1 DOT ???

Thanks!

-- 
-- luca


Re: [pygame] How the get a font size

2009-01-11 Thread Ian Mallett
As far as I know, there's no way to get the size of the font that way.  What
I do is name the font names in an intuitive way:
Font12 = pygame.font.Font(, 12)
Font18 = pygame.font.Font(, 18)
Font36 = pygame.font.Font(, 36)
Ian


Re: [pygame] How the get a font size

2009-01-11 Thread Noah Kantrowitz


On Jan 11, 2009, at 10:50 AM, Ian Mallett wrote:

As far as I know, there's no way to get the size of the font that  
way.  What I do is name the font names in an intuitive way:

Font12 = pygame.font.Font(, 12)
Font18 = pygame.font.Font(, 18)
Font36 = pygame.font.Font(, 36)
Ian


fonts = {
12: pygame,
18: pygame,
36: pygame,
}

Not to be logical or something.

--Noah