From b7ca6e4405983b0893b8056581c10d9250d45fac Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Sun, 24 Apr 2016 22:22:58 +0200 Subject: [PATCH 1/3] consequently use conversion functions instead of hardcoded formulas --- ocitysmap/indexlib/__init__.py | 4 ++-- ocitysmap/indexlib/multi_page_renderer.py | 4 ++-- ocitysmap/indexlib/renderer.py | 4 ++-- ocitysmap/layoutlib/commons.py | 5 +++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ocitysmap/indexlib/__init__.py b/ocitysmap/indexlib/__init__.py index bfbbd8b9..049e1590 100644 --- a/ocitysmap/indexlib/__init__.py +++ b/ocitysmap/indexlib/__init__.py @@ -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..0919a52c 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 From 2d0fec4fc35d0ec030c1f50d79151d43c5e250d7 Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Sun, 24 Apr 2016 22:52:12 +0200 Subject: [PATCH 2/3] missing import added --- ocitysmap/indexlib/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocitysmap/indexlib/__init__.py b/ocitysmap/indexlib/__init__.py index 049e1590..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) From 39637b87dc257b269a061bf57b2fdfb0f7ec944a Mon Sep 17 00:00:00 2001 From: Hartmut Holzgraefe Date: Sun, 24 Apr 2016 23:01:51 +0200 Subject: [PATCH 3/3] upper/lower case typo fix --- ocitysmap/layoutlib/commons.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ocitysmap/layoutlib/commons.py b/ocitysmap/layoutlib/commons.py index 0919a52c..400aff68 100644 --- a/ocitysmap/layoutlib/commons.py +++ b/ocitysmap/layoutlib/commons.py @@ -24,7 +24,7 @@ # PT/metrics conversion routines PT_PER_INCH = 72.0 -MM_per_INCH = 25.4 +MM_PER_INCH = 25.4 def convert_pt_to_dots(pt, dpi = PT_PER_INCH): return float(pt * dpi) / PT_PER_INCH