Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/olpcgames/pangofont.py
diff options
context:
space:
mode:
Diffstat (limited to 'olpcgames/pangofont.py')
-rw-r--r--olpcgames/pangofont.py54
1 files changed, 27 insertions, 27 deletions
diff --git a/olpcgames/pangofont.py b/olpcgames/pangofont.py
index 441dfd1..c56c0f7 100644
--- a/olpcgames/pangofont.py
+++ b/olpcgames/pangofont.py
@@ -43,11 +43,11 @@ Note:
PangoFont -- is the Pango-specific rendering engine which allows
for the more involved cross-lingual rendering operations.
"""
-import pango
+from gi.repository import Pango
import logging
import pangocairo
import pygame.rect, pygame.image
-import gtk
+from gi.repository import Gtk
import struct
from pygame import surface
from pygame.font import Font
@@ -76,25 +76,25 @@ class PangoFont(object):
STYLE_* -- parameters for use with set_style
"""
- WEIGHT_BOLD = pango.WEIGHT_BOLD
- WEIGHT_HEAVY = pango.WEIGHT_HEAVY
- WEIGHT_LIGHT = pango.WEIGHT_LIGHT
- WEIGHT_NORMAL = pango.WEIGHT_NORMAL
- WEIGHT_SEMIBOLD = pango.WEIGHT_SEMIBOLD
- WEIGHT_ULTRABOLD = pango.WEIGHT_ULTRABOLD
- WEIGHT_ULTRALIGHT = pango.WEIGHT_ULTRALIGHT
- STYLE_NORMAL = pango.STYLE_NORMAL
- STYLE_ITALIC = pango.STYLE_ITALIC
- STYLE_OBLIQUE = pango.STYLE_OBLIQUE
+ WEIGHT_BOLD = Pango.Weight.BOLD
+ WEIGHT_HEAVY = Pango.Weight.HEAVY
+ WEIGHT_LIGHT = Pango.Weight.LIGHT
+ WEIGHT_NORMAL = Pango.Weight.NORMAL
+ WEIGHT_SEMIBOLD = Pango.Weight.SEMIBOLD
+ WEIGHT_ULTRABOLD = Pango.Weight.ULTRABOLD
+ WEIGHT_ULTRALIGHT = Pango.Weight.ULTRALIGHT
+ STYLE_NORMAL = Pango.Style.NORMAL
+ STYLE_ITALIC = Pango.Style.ITALIC
+ STYLE_OBLIQUE = Pango.Style.OBLIQUE
def __init__(self, family=None, size=None, bold=False, italic=False, underline=False, fd=None):
- """If you know what pango.FontDescription (fd) you want, pass it in as
+ """If you know what Pango.FontDescription (fd) you want, pass it in as
'fd'. Otherwise, specify any number of family, size, bold, or italic,
and we will try to match something up for you."""
# Always set the FontDescription (FIXME - only set it if the user wants
# to change something?)
if fd is None:
- fd = pango.FontDescription()
+ fd = Pango.FontDescription()
if family is not None:
fd.set_family(family)
if size is not None:
@@ -173,7 +173,7 @@ class PangoFont(object):
return self.fd.get_weight()
def get_bold( self ):
"""Return whether our font's weight is bold (or above)"""
- return self.fd.get_weight() >= pango.WEIGHT_BOLD
+ return self.fd.get_weight() >= Pango.Weight.BOLD
def set_italic( self, italic=True ):
"""Set our "italic" value (style)"""
@@ -202,13 +202,13 @@ class PangoFont(object):
def _createLayout( self, text ):
"""Produces a Pango layout describing this text in this font"""
# create layout
- layout = pango.Layout(gtk.gdk.pango_context_get())
+ layout = Pango.Layout(gtk.gdk.pango_context_get())
layout.set_font_description(self.fd)
if self.underline:
attrs = layout.get_attributes()
if not attrs:
- attrs = pango.AttrList()
- attrs.insert(pango.AttrUnderline(pango.UNDERLINE_SINGLE, 0, 32767))
+ attrs = Pango.AttrList()
+ attrs.insert(Pango.AttrUnderline(Pango.Underline.SINGLE, 0, 32767))
layout.set_attributes( attrs )
layout.set_text(text)
return layout
@@ -227,7 +227,7 @@ class PangoFont(object):
## """Determine inter-line spacing for the font"""
## font = self.get_context().load_font( self.fd )
## metrics = font.get_metrics()
-## return pango.PIXELS( metrics.get_ascent() )
+## return Pango.PIXELS( metrics.get_ascent() )
## def get_height( self ):
## def get_ascent( self ):
## def get_descent( self ):
@@ -237,12 +237,12 @@ class SysFont(PangoFont):
"""Construct a PangoFont from a font description (name), size in pixels,
bold, and italic designation. Similar to SysFont from Pygame."""
def __init__(self, name, size, bold=False, italic=False):
- fd = pango.FontDescription(name)
- fd.set_absolute_size(size*pango.SCALE)
+ fd = Pango.FontDescription(name)
+ fd.set_absolute_size(size*Pango.SCALE)
if bold:
- fd.set_weight(pango.WEIGHT_BOLD)
+ fd.set_weight(Pango.Weight.BOLD)
if italic:
- fd.set_style(pango.STYLE_OBLIQUE)
+ fd.set_style(Pango.Style.OBLIQUE)
super(SysFont, self).__init__(fd=fd)
# originally defined a new class, no reason for that...
@@ -256,7 +256,7 @@ def fontByDesc(desc="",bold=False,italic=False):
"""Constructs a FontDescription from the given string representation.
The format of the fontByDesc string representation is passed directly
-to the pango.FontDescription constructor and documented at:
+to the Pango.FontDescription constructor and documented at:
http://www.pygtk.org/docs/pygtk/class-pangofontdescription.html#constructor-pangofontdescription
@@ -300,11 +300,11 @@ Expanded
Extra-Expanded
Ultra-Expanded the widest width
"""
- fd = pango.FontDescription(name)
+ fd = Pango.FontDescription(name)
if bold:
- fd.set_weight(pango.WEIGHT_BOLD)
+ fd.set_weight(Pango.Weight.BOLD)
if italic:
- fd.set_style(pango.STYLE_OBLIQUE)
+ fd.set_style(Pango.Style.OBLIQUE)
return PangoFont(fd=fd)
def get_init():