Using the GTK+-way to render text
svn: r5715
This commit is contained in:
parent
312696477f
commit
cd265d7fb3
@ -103,7 +103,7 @@ class PersonBoxWidget_cairo( gtk.DrawingArea):
|
|||||||
self.hightlight = False
|
self.hightlight = False
|
||||||
self.connect("expose_event", self.expose)
|
self.connect("expose_event", self.expose)
|
||||||
self.connect("realize", self.realize)
|
self.connect("realize", self.realize)
|
||||||
self.text = "Cairo"
|
self.text = ""
|
||||||
if self.person:
|
if self.person:
|
||||||
self.text = self.fh.format_person(self.person,self.maxlines)
|
self.text = self.fh.format_person(self.person,self.maxlines)
|
||||||
alive = Utils.probably_alive(self.person,self.fh.db)
|
alive = Utils.probably_alive(self.person,self.fh.db)
|
||||||
@ -128,7 +128,6 @@ class PersonBoxWidget_cairo( gtk.DrawingArea):
|
|||||||
else:
|
else:
|
||||||
self.bgcolor = (0.9,0.9,0.9)
|
self.bgcolor = (0.9,0.9,0.9)
|
||||||
self.bordercolor = (0,0,0)
|
self.bordercolor = (0,0,0)
|
||||||
self.lines = self.text.split("\n")
|
|
||||||
self.image = image
|
self.image = image
|
||||||
try:
|
try:
|
||||||
self.img_surf = cairo.ImageSurface.create_from_png(image)
|
self.img_surf = cairo.ImageSurface.create_from_png(image)
|
||||||
@ -148,19 +147,15 @@ class PersonBoxWidget_cairo( gtk.DrawingArea):
|
|||||||
|
|
||||||
def realize(self,widget):
|
def realize(self,widget):
|
||||||
self.context = self.window.cairo_create()
|
self.context = self.window.cairo_create()
|
||||||
e = self.context.font_extents()
|
self.textlayout = self.context.create_layout()
|
||||||
textheight = len(self.lines) * e[2]
|
self.textlayout.set_text(self.text)
|
||||||
textwidth = 1
|
s = self.textlayout.get_pixel_size()
|
||||||
for txt in self.lines:
|
xmin = s[0] + 12
|
||||||
le = self.context.text_extents(txt)
|
ymin = s[1] + 11
|
||||||
textwidth = max(textwidth,le[4])
|
|
||||||
xmin = textwidth + 12
|
|
||||||
ymin = textheight + 11
|
|
||||||
if self.image:
|
if self.image:
|
||||||
xmin += self.img_surf.get_width()
|
xmin += self.img_surf.get_width()
|
||||||
ymin = max( ymin,self.img_surf.get_height()+4)
|
ymin = max( ymin,self.img_surf.get_height()+4)
|
||||||
self.set_size_request(max(xmin,120),max(ymin,25))
|
self.set_size_request(max(xmin,120),max(ymin,25))
|
||||||
self.text_gc = self.window.new_gc()
|
|
||||||
|
|
||||||
def expose(self,widget,event):
|
def expose(self,widget,event):
|
||||||
alloc = self.get_allocation()
|
alloc = self.get_allocation()
|
||||||
@ -210,6 +205,11 @@ class PersonBoxWidget_cairo( gtk.DrawingArea):
|
|||||||
self.context.set_source_surface( self.img_surf,alloc.width-4-self.img_surf.get_width(),1)
|
self.context.set_source_surface( self.img_surf,alloc.width-4-self.img_surf.get_width(),1)
|
||||||
self.context.paint()
|
self.context.paint()
|
||||||
|
|
||||||
|
# text
|
||||||
|
self.context.move_to(5,4)
|
||||||
|
self.context.set_source_rgb( 0,0,0)
|
||||||
|
self.context.show_layout( self.textlayout)
|
||||||
|
|
||||||
#border
|
#border
|
||||||
if self.hightlight:
|
if self.hightlight:
|
||||||
self.context.set_line_width(5)
|
self.context.set_line_width(5)
|
||||||
@ -219,14 +219,6 @@ class PersonBoxWidget_cairo( gtk.DrawingArea):
|
|||||||
self.context.set_source_rgb( self.bordercolor[0], self.bordercolor[1], self.bordercolor[2])
|
self.context.set_source_rgb( self.bordercolor[0], self.bordercolor[1], self.bordercolor[2])
|
||||||
self.context.stroke()
|
self.context.stroke()
|
||||||
|
|
||||||
e = self.context.font_extents()
|
|
||||||
ypos = 5+e[0]
|
|
||||||
for txt in self.lines:
|
|
||||||
self.context.move_to(5,ypos)
|
|
||||||
self.context.set_source_rgb( 0,0,0)
|
|
||||||
self.context.show_text(txt)
|
|
||||||
ypos = ypos + e[2]
|
|
||||||
|
|
||||||
|
|
||||||
class PersonBoxWidget( gtk.DrawingArea):
|
class PersonBoxWidget( gtk.DrawingArea):
|
||||||
def __init__(self,fh,person,maxlines,image=None):
|
def __init__(self,fh,person,maxlines,image=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user