maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH 18/22] indexlib: add min_drawing_width() method


From: Thomas Petazzoni
Subject: [Maposmatic-dev] [PATCH 18/22] indexlib: add min_drawing_width() method
Date: Fri, 30 Mar 2012 13:00:35 +0200

Signed-off-by: Thomas Petazzoni <address@hidden>
---
 ocitysmap2/indexlib/commons.py |   24 +++++++++++++++++-------
 1 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/ocitysmap2/indexlib/commons.py b/ocitysmap2/indexlib/commons.py
index 8143ebc..f4c19bb 100644
--- a/ocitysmap2/indexlib/commons.py
+++ b/ocitysmap2/indexlib/commons.py
@@ -122,6 +122,13 @@ class IndexItem:
                 % (repr(self.label), self.endpoint1, self.endpoint2,
                    repr(self.location_str), repr(self.page_number)))
 
+    def min_drawing_width(self, layout, em):
+        layout.set_text(self.label)
+        label_w = float(layout.get_size()[0]) / pango.SCALE
+        layout.set_text(self.location_str)
+        location_w = float(layout.get_size()[0]) / pango.SCALE
+        return (label_w + location_w + 2 * em)
+
     def draw(self, rtl, ctx, pc, layout, fascent, fheight,
              baseline_x, baseline_y):
         """Draw this index item to the provided Cairo context. It prints the
@@ -142,14 +149,9 @@ class IndexItem:
         """
 
         if not self.location_str:
-            square_str = '???'
-        else:
-            square_str = self.location_str
-
-        if self.page_number is None:
-            location_str = square_str
+            location_str = '???'
         else:
-            location_str = "%d, %s" % (self.page_number, square_str)
+            location_str = self.location_str
 
         ctx.save()
         if not rtl:
@@ -211,6 +213,14 @@ class IndexItem:
             self.location_str = "%s-%s" % (min(ep1_label, ep2_label),
                                            max(ep1_label, ep2_label))
 
+        if self.page_number is not None:
+            if grid.rtl:
+                self.location_str = "%s, %d" % (self.location_str,
+                                                self.page_number)
+            else:
+                self.location_str = "%d, %s" % (self.page_number,
+                                                self.location_str)
+
 if __name__ == "__main__":
     import cairo
     import pangocairo
-- 
1.7.4.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]