Package pycocoa :: Module fonts :: Class Font
[frames] | no frames]

Class Font

          object --+        
                   |        
internals._Objectype --+    
                       |    
        baseTypes._Type0 --+
                           |
                          Font

Python Font Type, wrapping ObjC NSFont.

Instance Methods
 
__init__(self, family_or_font, size=0, traits=0, weight=5)
New Font.
 
__str__(self)
str(x)
 
resize(self, size)
Get this font in an other point size.
 
size2(self, bstr)
Get the size of a string.
 
sizedup(self, points)
Return a font with increased point size.
 
traitsup(self, *traits)
Return a font with updated traits.

Inherited from baseTypes._Type0: __repr__, type2strepr

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties
  count
Get the number of glyphs (int).
  family
Get the font family name (str).
  height
Get the line height (float or int).
  heightAscender
Get the ascender height (float).
  heightBaseline
Get the baseline offset (float or int).
  heightCap
Get the cap height (float or int).
  heightDescender
Get the descender height (float).
  heightLeading
Get the leading height (float or int).
  heightUnderline
Get the underline position (float).
  heightX
Get the x height (float or int).
  isBold
Get the Bold trait (bool).
  isCompressed
Get the Compressed trait (bool).
  isCondensed
Get the Condensed trait (bool).
  isExpanded
Get the Expanded trait (bool).
  isItalic
Get the Italic trait (bool).
  isMonoSpace
Get the MonoSpace trait (bool).
  isNarrow
Get the Narrow trait (bool).
  isPoster
Get the Poster trait (bool).
  isSansSerif
Get the SansSerif "trait" (bool).
  isSmallCaps
Get the SmallCaps trait (bool).
  isUnBold
Get the UnBold "trait" (bool).
  isUnItalic
Get the UnItalic "trait" (bool).
  isVertical
Get the Vertical "trait" (bool or None if unknown).
  name
Get the font name (str).
  NS
Get the ObjC instance (NSFont).
  size
Get the point size of the font (float or int).
  slant
Get the italic angle (float, int or None).
  traits
Get all font traits (FontTraits mask).
  vertical
Get the vertical version of this font (Font or None).
  weight
Get the book weight of the font (int or None).

Inherited from baseTypes._Type0: NSDelegate

Inherited from internals._Objectype: typename

Inherited from object: __class__

Method Details

__init__(self, family_or_font, size=0, traits=0, weight=5)
(Constructor)

 

New Font.

Parameters:
  • family_or_font - Generic font name (str, Str, NSStr) like "Times" or "Helvetica" or a Font, NSFont or NSFontDescriptor instance.
  • size - Desired point size (int), zero for any.
  • traits - Desired font traits (str or FontTraits mask).
  • weigth - Desired book weight (FontWeigt, int) in range 0..15, where 0=Light, 5=Regular, 9=Bold and 15=Heavy.
Raises:
  • FontError - No such family_or_font.
  • FontTraitError - Mutually exclusive traits.
  • TypeError - Invalid family_or_font.
  • ValueError - Invalid weight.
Overrides: object.__init__

Note: The new Font may not exhibit the desired traits and weight. The weight is ignored if traits include FontTrait.Bold, both traits and weight are ignored if family_or_font is NSFontDescriptor.

See Also: Function fontsOf to obtain all available fonts of a particular font family.

__str__(self)
(Informal representation operator)

 

str(x)

Overrides: object.__str__
(inherited documentation)

resize(self, size)

 

Get this font in an other point size.

Parameters:
  • size - Desired point size (int).
Returns:
The other or this font (Font).

See Also: Font.__init__ for errors raised.

size2(self, bstr)

 

Get the size of a string.

Parameters:
  • bstr - The string (str, bytes or Str).
Returns:
2-Tuple (width, height) in (float or int).

sizedup(self, points)

 

Return a font with increased point size.

Parameters:
  • points - Point size to add (int).
Returns:
The other or this font (Font).

See Also: Font.__init__ for errors raised.

traitsup(self, *traits)

 

Return a font with updated traits.

Parameters:
  • traits - Traits to update (str or FontTraits mask).
Returns:
The other or this font (Font).

See Also: Font.__init__ for errors raised.


Property Details

count

Get the number of glyphs (int).

Get Method:
count(self) - Get the number of glyphs (int).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

family

Get the font family name (str).

Get Method:
family(self) - Get the font family name (str).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

height

Get the line height (float or int).

Get Method:
height(self) - Get the line height (float or int).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

Note: The line height is the sum of the tallest ascender, tallest descender and leading heights.

heightAscender

Get the ascender height (float).

Get Method:
heightAscender(self) - Get the ascender height (float).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

heightBaseline

Get the baseline offset (float or int).

Get Method:
heightBaseline(self) - Get the baseline offset (float or int).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

heightCap

Get the cap height (float or int).

Get Method:
heightCap(self) - Get the cap height (float or int).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

heightDescender

Get the descender height (float).

Get Method:
heightDescender(self) - Get the descender height (float).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

heightLeading

Get the leading height (float or int).

Get Method:
heightLeading(self) - Get the leading height (float or int).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

heightUnderline

Get the underline position (float).

Get Method:
heightUnderline(self) - Get the underline position (float).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

heightX

Get the x height (float or int).

Get Method:
heightX(self) - Get the x height (float or int).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isBold

Get the Bold trait (bool).

Get Method:
isBold(self) - Get the Bold trait (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isCompressed

Get the Compressed trait (bool).

Get Method:
isCompressed(self) - Get the Compressed trait (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isCondensed

Get the Condensed trait (bool).

Get Method:
isCondensed(self) - Get the Condensed trait (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isExpanded

Get the Expanded trait (bool).

Get Method:
isExpanded(self) - Get the Expanded trait (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isItalic

Get the Italic trait (bool).

Get Method:
isItalic(self) - Get the Italic trait (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isMonoSpace

Get the MonoSpace trait (bool).

Get Method:
isMonoSpace(self) - Get the MonoSpace trait (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isNarrow

Get the Narrow trait (bool).

Get Method:
isNarrow(self) - Get the Narrow trait (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isPoster

Get the Poster trait (bool).

Get Method:
isPoster(self) - Get the Poster trait (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isSansSerif

Get the SansSerif "trait" (bool).

Get Method:
isSansSerif(self) - Get the SansSerif "trait" (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isSmallCaps

Get the SmallCaps trait (bool).

Get Method:
isSmallCaps(self) - Get the SmallCaps trait (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isUnBold

Get the UnBold "trait" (bool).

Get Method:
isUnBold(self) - Get the UnBold "trait" (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isUnItalic

Get the UnItalic "trait" (bool).

Get Method:
isUnItalic(self) - Get the UnItalic "trait" (bool).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

isVertical

Get the Vertical "trait" (bool or None if unknown).

Get Method:
isVertical(self) - Get the Vertical "trait" (bool or None if unknown).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

name

Get the font name (str).

Get Method:
name(self) - Get the font name (str).
Set Method:
name(self, name) - Set the font name (str).

NS

Get the ObjC instance (NSFont).

Get Method:
NS(self) - Get the ObjC instance (NSFont).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

size

Get the point size of the font (float or int).

Get Method:
size(self) - Get the point size of the font (float or int).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

slant

Get the italic angle (float, int or None).

Get Method:
slant(self) - Get the italic angle (float, int or None).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

traits

Get all font traits (FontTraits mask).

Get Method:
traits(self) - Get all font traits (FontTraits mask).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

vertical

Get the vertical version of this font (Font or None).

Get Method:
vertical(self) - Get the vertical version of this font (Font or None).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.

weight

Get the book weight of the font (int or None).

Get Method:
weight(self) - Get the book weight of the font (int or None).
Set Method:
Read_Only(inst, value) - Throws an AttributeError, always.