diff --git a/ocitysmap/indexlib/__init__.py b/ocitysmap/indexlib/__init__.py index bfbbd8b9..fe134cb6 100644 --- a/ocitysmap/indexlib/__init__.py +++ b/ocitysmap/indexlib/__init__.py @@ -35,7 +35,7 @@ from indexer import StreetIndex from renderer import StreetIndexRenderer from commons import IndexCategory, IndexItem - + import ocitysmap.layoutlib.commons as UTILS logging.basicConfig(level=logging.DEBUG) random.seed(42) @@ -67,8 +67,8 @@ def __init__(self, rtl): def isrtl(self): return self.rtl - width = 2.5*(20 / 2.54) * 72 - height = 2.5*(29 / 2.54) * 72 + width = 2.5 * contert_mm_to_pt(210) + height = 2.5 * contert_mm_to_pt(297) surface = cairo.PDFSurface('/tmp/myindex.pdf', width, height) diff --git a/ocitysmap/indexlib/multi_page_renderer.py b/ocitysmap/indexlib/multi_page_renderer.py index 022980bb..8cfd569b 100644 --- a/ocitysmap/indexlib/multi_page_renderer.py +++ b/ocitysmap/indexlib/multi_page_renderer.py @@ -228,8 +228,8 @@ def render(self, dpi = UTILS.PT_PER_INCH): import commons import coords - width = 72*21./2.54 - height = 72*29.7/2.54 + width = UTILS.convert_mm_to_pt(210) + height = UTILS.convert_mm_to_pt(297) surface = cairo.PDFSurface('/tmp/myindex_render.pdf', width, height) diff --git a/ocitysmap/indexlib/renderer.py b/ocitysmap/indexlib/renderer.py index 0f739e12..ee5ae925 100644 --- a/ocitysmap/indexlib/renderer.py +++ b/ocitysmap/indexlib/renderer.py @@ -499,8 +499,8 @@ def _compute_columns_split(self, pc, rendering_style, logging.basicConfig(level=logging.DEBUG) - width = 72*21./2.54 - height = .75 * 72*29.7/2.54 + width = UTILS.convert_mm_to_pt(210) + height = .75 * UTILS.convert_mm_to_pt(294) random.seed(42) diff --git a/ocitysmap/layoutlib/commons.py b/ocitysmap/layoutlib/commons.py index 75959ad3..400aff68 100644 --- a/ocitysmap/layoutlib/commons.py +++ b/ocitysmap/layoutlib/commons.py @@ -24,12 +24,13 @@ # PT/metrics conversion routines PT_PER_INCH = 72.0 +MM_PER_INCH = 25.4 def convert_pt_to_dots(pt, dpi = PT_PER_INCH): return float(pt * dpi) / PT_PER_INCH def convert_mm_to_pt(mm): - return ((mm/10.0) / 2.54) * 72 + return float(mm) / MM_PER_INCH * PT_PER_INCH def convert_pt_to_mm(pt): - return (float(pt) * 10.0 * 2.54) / 72 + return float(pt) * MM_PER_INCH / PT_PER_INCH