Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Private Member Functions
MoinMoin.support.pygments.formatters.img.FontManager Class Reference

List of all members.

Public Member Functions

def __init__
def get_char_size
def get_font

Public Attributes

 font_name
 font_size
 fonts
 encoding

Private Member Functions

def _get_nix_font_path
def _create_nix
def _lookup_win
def _create_win

Detailed Description

Manages a set of fonts: normal, italic, bold, etc...

Definition at line 55 of file img.py.


Constructor & Destructor Documentation

def MoinMoin.support.pygments.formatters.img.FontManager.__init__ (   self,
  font_name,
  font_size = 14 
)

Definition at line 60 of file img.py.

00060 
00061     def __init__(self, font_name, font_size=14):
00062         self.font_name = font_name
00063         self.font_size = font_size
00064         self.fonts = {}
00065         self.encoding = None
00066         if sys.platform.startswith('win'):
00067             if not font_name:
00068                 self.font_name = DEFAULT_FONT_NAME_WIN
00069             self._create_win()
00070         else:
00071             if not font_name:
00072                 self.font_name = DEFAULT_FONT_NAME_NIX
00073             self._create_nix()


Member Function Documentation

Definition at line 83 of file img.py.

00083 
00084     def _create_nix(self):
00085         for name in STYLES['NORMAL']:
00086             path = self._get_nix_font_path(self.font_name, name)
00087             if path is not None:
00088                 self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
00089                 break
00090         else:
00091             raise FontNotFound('No usable fonts named: "%s"' %
00092                                self.font_name)
00093         for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
00094             for stylename in STYLES[style]:
00095                 path = self._get_nix_font_path(self.font_name, stylename)
00096                 if path is not None:
00097                     self.fonts[style] = ImageFont.truetype(path, self.font_size)
00098                     break
00099             else:
00100                 if style == 'BOLDITALIC':
00101                     self.fonts[style] = self.fonts['BOLD']
00102                 else:
00103                     self.fonts[style] = self.fonts['NORMAL']

Here is the call graph for this function:

Definition at line 119 of file img.py.

00119 
00120     def _create_win(self):
00121         try:
00122             key = _winreg.OpenKey(
00123                 _winreg.HKEY_LOCAL_MACHINE,
00124                 r'Software\Microsoft\Windows NT\CurrentVersion\Fonts')
00125         except EnvironmentError:
00126             try:
00127                 key = _winreg.OpenKey(
00128                     _winreg.HKEY_LOCAL_MACHINE,
00129                     r'Software\Microsoft\Windows\CurrentVersion\Fonts')
00130             except EnvironmentError:
00131                 raise FontNotFound('Can\'t open Windows font registry key')
00132         try:
00133             path = self._lookup_win(key, self.font_name, STYLES['NORMAL'], True)
00134             self.fonts['NORMAL'] = ImageFont.truetype(path, self.font_size)
00135             for style in ('ITALIC', 'BOLD', 'BOLDITALIC'):
00136                 path = self._lookup_win(key, self.font_name, STYLES[style])
00137                 if path:
00138                     self.fonts[style] = ImageFont.truetype(path, self.font_size)
00139                 else:
00140                     if style == 'BOLDITALIC':
00141                         self.fonts[style] = self.fonts['BOLD']
00142                     else:
00143                         self.fonts[style] = self.fonts['NORMAL']
00144         finally:
00145             _winreg.CloseKey(key)

Here is the call graph for this function:

def MoinMoin.support.pygments.formatters.img.FontManager._get_nix_font_path (   self,
  name,
  style 
) [private]

Definition at line 74 of file img.py.

00074 
00075     def _get_nix_font_path(self, name, style):
00076         exit, out = getstatusoutput('fc-list "%s:style=%s" file' %
00077                                     (name, style))
00078         if not exit:
00079             lines = out.splitlines()
00080             if lines:
00081                 path = lines[0].strip().strip(':')
00082                 return path

Here is the caller graph for this function:

def MoinMoin.support.pygments.formatters.img.FontManager._lookup_win (   self,
  key,
  basename,
  styles,
  fail = False 
) [private]

Definition at line 104 of file img.py.

00104 
00105     def _lookup_win(self, key, basename, styles, fail=False):
00106         for suffix in ('', ' (TrueType)'):
00107             for style in styles:
00108                 try:
00109                     valname = '%s%s%s' % (basename, style and ' '+style, suffix)
00110                     val, _ = _winreg.QueryValueEx(key, valname)
00111                     return val
00112                 except EnvironmentError:
00113                     continue
00114         else:
00115             if fail:
00116                 raise FontNotFound('Font %s (%s) not found in registry' %
00117                                    (basename, styles[0]))
00118             return None

Here is the caller graph for this function:

Get the character size.

Definition at line 146 of file img.py.

00146 
00147     def get_char_size(self):
00148         """
00149         Get the character size.
00150         """
00151         return self.fonts['NORMAL'].getsize('M')

def MoinMoin.support.pygments.formatters.img.FontManager.get_font (   self,
  bold,
  oblique 
)
Get the font based on bold and italic flags.

Definition at line 152 of file img.py.

00152 
00153     def get_font(self, bold, oblique):
00154         """
00155         Get the font based on bold and italic flags.
00156         """
00157         if bold and oblique:
00158             return self.fonts['BOLDITALIC']
00159         elif bold:
00160             return self.fonts['BOLD']
00161         elif oblique:
00162             return self.fonts['ITALIC']
00163         else:
00164             return self.fonts['NORMAL']
00165 


Member Data Documentation

Definition at line 64 of file img.py.

Definition at line 61 of file img.py.

Definition at line 62 of file img.py.

Definition at line 63 of file img.py.


The documentation for this class was generated from the following file: