diff --git a/src/ImgManip.py b/src/ImgManip.py
index 00e19486e..2a2b7efb3 100644
--- a/src/ImgManip.py
+++ b/src/ImgManip.py
@@ -51,7 +51,7 @@ import Utils
# resize_to_jpeg
#
#-------------------------------------------------------------------------
-def resize_to_jpeg(source, destination, width, height):
+def resize_to_jpeg(source, destination, width, height, crop=None):
"""
Create the destination, derived from the source, resizing it to the
specified size, while converting to JPEG.
@@ -64,10 +64,27 @@ def resize_to_jpeg(source, destination, width, height):
:type width: int
:param height: desired height of the destination image
:type height: int
+ :param crop: cropping coordinates
+ :type crop: array of integers ([start_x, start_y, end_x, end_y])
"""
import gtk
+
img = gtk.gdk.pixbuf_new_from_file(source)
- scaled = img.scale_simple(width, height, gtk.gdk.INTERP_BILINEAR)
+
+ if crop:
+ # Gramps cropping coorinates are [0, 100], so we need to convert to pixels
+ start_x = int((crop[0]/100.0)*img.get_width())
+ start_y = int((crop[1]/100.0)*img.get_height())
+ end_x = int((crop[2]/100.0)*img.get_width())
+ end_y = int((crop[3]/100.0)*img.get_height())
+
+ img = img.subpixbuf(start_x, start_y, end_x-start_x, end_y-start_y)
+
+ # Need to keep the ratio intact, otherwise scaled images look stretched
+ # if the dimensions aren't close in size
+ (width, height) = image_actual_size(width, height, img.get_width(), img.get_height())
+
+ scaled = img.scale_simple(int(width), int(height), gtk.gdk.INTERP_BILINEAR)
scaled.save(destination, 'jpeg')
#-------------------------------------------------------------------------
diff --git a/src/gen/plug/docgen/textdoc.py b/src/gen/plug/docgen/textdoc.py
index 17129c73f..90f8a8814 100644
--- a/src/gen/plug/docgen/textdoc.py
+++ b/src/gen/plug/docgen/textdoc.py
@@ -53,7 +53,7 @@ log = logging.getLogger(".textdoc")
# URL string pattern
#
#-------------------------------------------------------------------------
-URL_PATTERN = r'''(((https?|mailto):)(//([^/?#"]*))?([^?#"]*)(\?([^#"]*))?(#([^"]*))?)'''
+URL_PATTERN = r'''(((https?|mailto):)(//([^ /?#"]*))?([^ ?#"]*)(\?([^ #"]*))?(#([^ "]*))?)'''
#-------------------------------------------------------------------------
#
@@ -221,7 +221,7 @@ class TextDoc(object):
text = str(styledtext)
self.write_note(text, format, style_name)
- def write_text_citation(self, text, mark=None):
+ def write_text_citation(self, text, mark=None, links=None):
"""
Method to write text with GRAMPS citation marks.
"""
@@ -236,22 +236,22 @@ class TextDoc(object):
piecesplit = piece.split("")
if len(piecesplit) == 2:
self.start_superscript()
- self.write_text(piecesplit[0])
+ self.write_text(piecesplit[0], links=links)
self.end_superscript()
if not piecesplit[1]:
#text ended with ' ... '
continue
if not markset:
- self.write_text(piecesplit[1], mark)
+ self.write_text(piecesplit[1], mark, links=links)
markset = True
else:
- self.write_text(piecesplit[1])
+ self.write_text(piecesplit[1], links=links)
else:
if not markset:
- self.write_text(piece, mark)
+ self.write_text(piece, mark, links=links)
markset = True
else:
- self.write_text(piece)
+ self.write_text(piece, links=links)
def add_media_object(self, name, align, w_cm, h_cm, alt='', style_name=None, crop=None):
"""
diff --git a/src/gen/plug/report/utils.py b/src/gen/plug/report/utils.py
index cd6a6bd3d..63cb82c03 100644
--- a/src/gen/plug/report/utils.py
+++ b/src/gen/plug/report/utils.py
@@ -125,7 +125,7 @@ def place_name(db, place_handle):
# Functions commonly used in reports
#
#-------------------------------------------------------------------------
-def insert_image(database, doc, photo, w_cm=4.0, h_cm=4.0):
+def insert_image(database, doc, photo, w_cm=4.0, h_cm=4.0, alt=""):
"""
Insert pictures of a person into the document.
"""
@@ -136,7 +136,8 @@ def insert_image(database, doc, photo, w_cm=4.0, h_cm=4.0):
if mime_type and mime_type.startswith("image"):
filename = media_path_full(database, media_object.get_path())
if os.path.exists(filename):
- doc.add_media_object(filename, "right", w_cm, h_cm)
+ doc.add_media_object(filename, "right", w_cm, h_cm, alt=alt,
+ style_name="DDR-Caption", crop=photo.get_rectangle())
else:
# TODO: Replace this with a callback
from QuestionDialog import WarningDialog
diff --git a/src/plugins/docgen/HtmlDoc.py b/src/plugins/docgen/HtmlDoc.py
index b58e643de..318f3122f 100644
--- a/src/plugins/docgen/HtmlDoc.py
+++ b/src/plugins/docgen/HtmlDoc.py
@@ -48,7 +48,7 @@ from gen.ggettext import gettext as _
#------------------------------------------------------------------------
import ImgManip
import const
-from gen.plug.docgen import BaseDoc, TextDoc, FONT_SANS_SERIF
+from gen.plug.docgen import BaseDoc, TextDoc, FONT_SANS_SERIF, URL_PATTERN
from libhtmlbackend import HtmlBackend, process_spaces
from libhtml import Html
@@ -63,6 +63,13 @@ LOG = logging.getLogger(".htmldoc")
_TEXTDOCSCREEN = 'grampstextdoc.css'
_HTMLSCREEN = 'grampshtml.css'
+#------------------------------------------------------------------------
+#
+# Set up to make links clickable
+#
+#------------------------------------------------------------------------
+_CLICKABLE = r'''\1'''
+
#------------------------------------------------------------------------
#
# HtmlDoc
@@ -297,17 +304,21 @@ class HtmlDoc(BaseDoc, TextDoc):
self.htmllist[-2] += self.htmllist[-1]
self.htmllist.pop()
- def __write_text(self, text, mark=None, markup=False):
+ def __write_text(self, text, mark=None, markup=False, links=False):
"""
@param text: text to write.
@param mark: IndexMark to use for indexing (if supported)
@param markup: True if text already contains markup info.
Then text will no longer be escaped
+ @param links: make URLs clickable if True
"""
if not markup:
text = self._backend.ESCAPE_FUNC()(text)
if self.__title_written == 0 :
self.title += text
+ if links == True:
+ import re
+ text = re.sub(URL_PATTERN, _CLICKABLE, text)
self.htmllist[-1] += text
def __empty_char(self):
@@ -323,7 +334,7 @@ class HtmlDoc(BaseDoc, TextDoc):
"""
if text != "":
self._empty = 0
- self.__write_text(text, mark)
+ self.__write_text(text, mark, links=links)
def write_title(self):
"""
@@ -461,6 +472,7 @@ class HtmlDoc(BaseDoc, TextDoc):
some way. Eg, a textdoc could remove all tags, or could make sure
a link is clickable. HtmlDoc will show the html as pure text, so
no escaping will happen.
+ links: bool, make URLs clickable if True
"""
text = str(styledtext)
@@ -469,7 +481,7 @@ class HtmlDoc(BaseDoc, TextDoc):
#just dump the note out as it is. Adding markup would be dangerous
# as it could destroy the html. If html code, one can do the
self.start_paragraph(style_name)
- self.__write_text(text, markup=True)
+ self.__write_text(text, markup=True, links=links)
self.end_paragraph()
else:
s_tags = styledtext.get_tags()
@@ -502,7 +514,7 @@ class HtmlDoc(BaseDoc, TextDoc):
self._empty = 1 # para is empty
if linenb > 1:
self.htmllist[-1] += Html('br')
- self.__write_text(line, markup=True)
+ self.__write_text(line, markup=True, links=links)
self._empty = 0 # para is not empty
linenb += 1
if inpara == True:
@@ -528,17 +540,31 @@ class HtmlDoc(BaseDoc, TextDoc):
imdir = self._backend.datadirfull()
try:
- ImgManip.resize_to_jpeg(name, imdir + os.sep + refname, size, size)
+ ImgManip.resize_to_jpeg(name, imdir + os.sep + refname, size, size, crop=crop)
except:
LOG.warn(_("Could not create jpeg version of image %(name)s") %
{'name' : name})
return
if pos not in ["right", "left"] :
- self.htmllist[-1] += Html('img', src= imdir + os.sep + refname,
+ if len(alt):
+ self.htmllist[-1] += Html('div') + (
+ Html('img', src= imdir + os.sep + refname,
+ border = '0', alt=alt),
+ Html('p', class_="DDR-Caption") + alt
+ )
+ else:
+ self.htmllist[-1] += Html('img', src= imdir + os.sep + refname,
border = '0', alt=alt)
else:
- self.htmllist[-1] += Html('img', src= imdir + os.sep + refname,
+ if len(alt):
+ self.htmllist[-1] += Html('div', style_="float: %s; padding: 5px; margin: 0;" % pos) + (
+ Html('img', src= imdir + os.sep + refname,
+ border = '0', alt=alt),
+ Html('p', class_="DDR-Caption") + alt
+ )
+ else:
+ self.htmllist[-1] += Html('img', src= imdir + os.sep + refname,
border = '0', alt=alt, align=pos)
def page_break(self):
diff --git a/src/plugins/docgen/ODFDoc.py b/src/plugins/docgen/ODFDoc.py
index 09b965ad6..e33183b27 100644
--- a/src/plugins/docgen/ODFDoc.py
+++ b/src/plugins/docgen/ODFDoc.py
@@ -1038,9 +1038,16 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
(act_width, act_height) = ImgManip.image_actual_size(x_cm, y_cm, x, y)
if len(alt):
- self.cntnt.write(' ' % (pos, tag, act_width))
- self.cntnt.write(' ' % act_height)
- self.cntnt.write('' % style_name)
+ self.cntnt.write(
+ ' ' +
+ ' ' % act_height +
+ '' % style_name
+ )
self.cntnt.write(
'' % mark.level
)
- self.cntnt.write(escape(text, _esc_map))
+ self.cntnt.write(text)
def _write_manifest(self):
"""