Permalink
Browse files

Added stuff for stereotypes

  • Loading branch information...
amolenaar committed Jun 27, 2011
1 parent f429e37 commit b2478000334f9b1b40fb9494d1cc60a37cb21385
Showing with 31 additions and 8 deletions.
  1. +2 −0 gaphor/diagram/classes/klass.py
  2. +4 −5 gaphor/diagram/compartment.py
  3. +25 −3 gaphor/diagram/textelement.py
@@ -52,7 +52,9 @@ def __init__(self, id=None):
ClassifierItem.__init__(self, id)
self.drawing_style = self.DRAW_COMPARTMENT
self._attributes = self.create_compartment('attributes')
+ self._attributes.font = self.style.feature_font
self._operations = self.create_compartment('operations')
+ self._operations.font = self.style.feature_font
self._operations.use_extra_space = True
self.watch('subject<Class>.ownedOperation', self.on_class_owned_operation)\
@@ -8,8 +8,7 @@
from gaphor import UML
from gaphor.diagram.diagramitem import DiagramItem
from gaphor.diagram.nameditem import NamedItem
-from textelement import text_extents
-from gaphas.util import text_align
+from textelement import text_extents, text_align
class FeatureItem(object):
@@ -108,6 +107,7 @@ def __init__(self, name, owner, id=None):
self.width = 0
self.height = 0
self.title = None
+ self.font = None
self.title_height = 0
self.use_extra_space = False
@@ -173,6 +173,8 @@ def draw(self, context):
cr.translate(padding[1], padding[0])
offset = 0
if self.title:
+ text_align(cr, self.owner.width / 2.0, padding[0],
+ self.title, font=self.font, align_y=1)
offset += self.title_height + vspacing
for item in self:
cr.save()
@@ -534,9 +536,6 @@ def draw_compartment(self, context):
cr.line_to(self.width, 0)
cr.stroke()
- if comp.title:
- padding = self.style.compartment_padding
- text_align(cr, self.width / 2.0, padding[0], comp.title, align_y=1)
try:
comp.draw(context)
finally:
@@ -35,20 +35,42 @@ def text_extents(cr, text, font=None, multiline=False):
return layout.get_pixel_size()
-def text_align(cr, x, y, text, align_x=0, align_y=0, padding_x=0, padding_y=0):
+def text_align(cr, x, y, text, font, align_x=0, align_y=0, padding_x=0, padding_y=0):
"""
Draw text relative to (x, y).
x, y - coordinates
text - text to print (utf8)
+ font - The font to render in
align_x - -1 (top), 0 (middle), 1 (bottom)
align_y - -1 (left), 0 (center), 1 (right)
padding_x - padding (extra offset), always > 0
padding_y - padding (extra offset), always > 0
"""
+ if not isinstance(cr, cairo.Context):
+ return
+
cr = pangocairo.CairoContext(cr)
layout = cr.create_layout()
- layout.set_font_description(pango.FontDescription(self._style.font))
- layout.set_text(self.text)
+ print 'align with font', font
+ if font:
+ layout.set_font_description(font)
+ layout.set_text(text)
+ w, h = layout.get_pixel_size()
+
+ if align_x == 0:
+ x = 0.5 - (w / 2) + x
+ elif align_x < 0:
+ x = -w + x - padding_x
+ else:
+ x = x + padding_x
+ if align_y == 0:
+ y = 0.5 - (h / 2) + y
+ elif align_y < 0:
+ y = -h + y - padding_y
+ else:
+ y = y + padding_y
+ cr.move_to(x, y)
+ cr.update_layout(layout)
cr.show_layout(layout)

0 comments on commit b247800

Please sign in to comment.