From 4a76aaa63c2285ec1aaf4c40b02c60b8461adaea Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Fri, 8 Feb 2002 00:28:47 +0000 Subject: [PATCH] Fix image scaling svn: r763 --- gramps/src/RelLib.py | 3 ++- gramps/src/docgen/OpenOfficeDoc.py | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/gramps/src/RelLib.py b/gramps/src/RelLib.py index 3d62dda37..e04c0a255 100644 --- a/gramps/src/RelLib.py +++ b/gramps/src/RelLib.py @@ -26,6 +26,7 @@ __author__ = "Don Allingham" from re import compile from Date import Date, compare_dates, not_too_old from string import strip +import os CONF_VERY_HIGH = 4 CONF_HIGH = 3 @@ -498,7 +499,7 @@ class Photo(SourceNote): def setPath(self,path): """set the file path to the passed path""" - self.path = path + self.path = os.path.normpath(path) def getPath(self): """return the file path""" diff --git a/gramps/src/docgen/OpenOfficeDoc.py b/gramps/src/docgen/OpenOfficeDoc.py index 9fe590e05..049a5f388 100644 --- a/gramps/src/docgen/OpenOfficeDoc.py +++ b/gramps/src/docgen/OpenOfficeDoc.py @@ -226,13 +226,17 @@ class OpenOfficeDoc(TextDoc): self._write_zip() def add_photo(self,name,pos,x_cm,y_cm): - import gtk - import GdkImlib - image = GdkImlib.Image(name) - scale = float(image.rgb_width)/float(image.rgb_height) - act_width = int(((x_cm * scale)*2.54)*72) - act_height = int(((y_cm * scale)*2.54)*72) + image = ImgManip.ImgManip(name) + (x,y) = image.size() + aspect_ratio = float(x)/float(y) + + if aspect_ratio > x_cm/y_cm: + act_width = x_cm + act_height = y_cm/aspect_ratio + else: + act_height = y_cm + act_width = x_cm*aspect_ratio self.photo_list.append((name,act_width,act_height)) @@ -251,8 +255,8 @@ class OpenOfficeDoc(TextDoc): self.f.write('draw:name="') self.f.write(tag) self.f.write('" text:anchor-type="paragraph" ') - self.f.write('svg:width="%.3fcm" ' % (x_cm*scale)) - self.f.write('svg:height="%.3fcm" ' % (y_cm*scale)) + self.f.write('svg:width="%.3fcm" ' % act_width) + self.f.write('svg:height="%.3fcm" ' % act_height) self.f.write('draw:z-index="0" ') self.f.write('xlink:href="#Pictures/') self.f.write(base)