[Top][All Lists]
[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
- [Maposmatic-dev] [PATCH 07/22] indexlib: add page_number to IndexItem, (continued)
- [Maposmatic-dev] [PATCH 07/22] indexlib: add page_number to IndexItem, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 02/22] coords: add BoundingBox::as_javascript() method, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 08/22] indexlib: do not raise exception when index is empty, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 09/22] indexlib: villages section is not of street type, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 10/22] renderers: pass the db connection to the Renderer class constructor, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 12/22] indexlib: render page number as part of the street/amenity location, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 15/22] indexlib: properly differentiate the page_number=None and page_number=0 cases, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 13/22] multi-page: add in dex rendering with a new MultiPageStreetIndexRenderer cl ass, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 11/22] multi-page: prepare data for index generation, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 14/22] multi-page: remove multiple debugging outputs, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 18/22] indexlib: add min_drawing_width() method,
Thomas Petazzoni <=
- [Maposmatic-dev] [PATCH 19/22] MultiPageStreetIndexRenderer: remove debugging background rectangle, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 16/22] multi-page: in the street index, start page numbering at 1, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 21/22] MultiPageStreetIndexRenderer: automatically compute the number of columns, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 20/22] MultiPageStreetIndexRenderer: reduce size of default font, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 22/22] multi-page: minor fixups for compatibility with Gaƫl's work to remo ve the scaling, Thomas Petazzoni, 2012/03/30
- [Maposmatic-dev] [PATCH 17/22] index for multi-page: improve page_number handling, Thomas Petazzoni, 2012/03/30
- Re: [Maposmatic-dev] Implementation of a multi-page renderer, Jeroen van Rijn, 2012/03/30