Patch by Adam Stein <adam@csh.rit.edu > - Partial completion of "0002513: Using section/region on media_ref as thumbnail on reports"
svn: r17917
This commit is contained in:
parent
c9f0f2c8d7
commit
bb6ad450e3
@ -51,7 +51,7 @@ import Utils
|
|||||||
# resize_to_jpeg
|
# 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
|
Create the destination, derived from the source, resizing it to the
|
||||||
specified size, while converting to JPEG.
|
specified size, while converting to JPEG.
|
||||||
@ -64,10 +64,27 @@ def resize_to_jpeg(source, destination, width, height):
|
|||||||
:type width: int
|
:type width: int
|
||||||
:param height: desired height of the destination image
|
:param height: desired height of the destination image
|
||||||
:type height: int
|
:type height: int
|
||||||
|
:param crop: cropping coordinates
|
||||||
|
:type crop: array of integers ([start_x, start_y, end_x, end_y])
|
||||||
"""
|
"""
|
||||||
import gtk
|
import gtk
|
||||||
|
|
||||||
img = gtk.gdk.pixbuf_new_from_file(source)
|
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')
|
scaled.save(destination, 'jpeg')
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
|
@ -53,7 +53,7 @@ log = logging.getLogger(".textdoc")
|
|||||||
# URL string pattern
|
# URL string pattern
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
URL_PATTERN = r'''(((https?|mailto):)(//([^/?#"]*))?([^?#"]*)(\?([^#"]*))?(#([^"]*))?)'''
|
URL_PATTERN = r'''(((https?|mailto):)(//([^ /?#"]*))?([^ ?#"]*)(\?([^ #"]*))?(#([^ "]*))?)'''
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -221,7 +221,7 @@ class TextDoc(object):
|
|||||||
text = str(styledtext)
|
text = str(styledtext)
|
||||||
self.write_note(text, format, style_name)
|
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 <super> citation marks.
|
Method to write text with GRAMPS <super> citation marks.
|
||||||
"""
|
"""
|
||||||
@ -236,22 +236,22 @@ class TextDoc(object):
|
|||||||
piecesplit = piece.split("</super>")
|
piecesplit = piece.split("</super>")
|
||||||
if len(piecesplit) == 2:
|
if len(piecesplit) == 2:
|
||||||
self.start_superscript()
|
self.start_superscript()
|
||||||
self.write_text(piecesplit[0])
|
self.write_text(piecesplit[0], links=links)
|
||||||
self.end_superscript()
|
self.end_superscript()
|
||||||
if not piecesplit[1]:
|
if not piecesplit[1]:
|
||||||
#text ended with ' ... </super>'
|
#text ended with ' ... </super>'
|
||||||
continue
|
continue
|
||||||
if not markset:
|
if not markset:
|
||||||
self.write_text(piecesplit[1], mark)
|
self.write_text(piecesplit[1], mark, links=links)
|
||||||
markset = True
|
markset = True
|
||||||
else:
|
else:
|
||||||
self.write_text(piecesplit[1])
|
self.write_text(piecesplit[1], links=links)
|
||||||
else:
|
else:
|
||||||
if not markset:
|
if not markset:
|
||||||
self.write_text(piece, mark)
|
self.write_text(piece, mark, links=links)
|
||||||
markset = True
|
markset = True
|
||||||
else:
|
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):
|
def add_media_object(self, name, align, w_cm, h_cm, alt='', style_name=None, crop=None):
|
||||||
"""
|
"""
|
||||||
|
@ -125,7 +125,7 @@ def place_name(db, place_handle):
|
|||||||
# Functions commonly used in reports
|
# 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.
|
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"):
|
if mime_type and mime_type.startswith("image"):
|
||||||
filename = media_path_full(database, media_object.get_path())
|
filename = media_path_full(database, media_object.get_path())
|
||||||
if os.path.exists(filename):
|
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:
|
else:
|
||||||
# TODO: Replace this with a callback
|
# TODO: Replace this with a callback
|
||||||
from QuestionDialog import WarningDialog
|
from QuestionDialog import WarningDialog
|
||||||
|
@ -48,7 +48,7 @@ from gen.ggettext import gettext as _
|
|||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
import ImgManip
|
import ImgManip
|
||||||
import const
|
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 libhtmlbackend import HtmlBackend, process_spaces
|
||||||
from libhtml import Html
|
from libhtml import Html
|
||||||
|
|
||||||
@ -63,6 +63,13 @@ LOG = logging.getLogger(".htmldoc")
|
|||||||
_TEXTDOCSCREEN = 'grampstextdoc.css'
|
_TEXTDOCSCREEN = 'grampstextdoc.css'
|
||||||
_HTMLSCREEN = 'grampshtml.css'
|
_HTMLSCREEN = 'grampshtml.css'
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Set up to make links clickable
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
_CLICKABLE = r'''<a href="\1">\1</a>'''
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# HtmlDoc
|
# HtmlDoc
|
||||||
@ -297,17 +304,21 @@ class HtmlDoc(BaseDoc, TextDoc):
|
|||||||
self.htmllist[-2] += self.htmllist[-1]
|
self.htmllist[-2] += self.htmllist[-1]
|
||||||
self.htmllist.pop()
|
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 text: text to write.
|
||||||
@param mark: IndexMark to use for indexing (if supported)
|
@param mark: IndexMark to use for indexing (if supported)
|
||||||
@param markup: True if text already contains markup info.
|
@param markup: True if text already contains markup info.
|
||||||
Then text will no longer be escaped
|
Then text will no longer be escaped
|
||||||
|
@param links: make URLs clickable if True
|
||||||
"""
|
"""
|
||||||
if not markup:
|
if not markup:
|
||||||
text = self._backend.ESCAPE_FUNC()(text)
|
text = self._backend.ESCAPE_FUNC()(text)
|
||||||
if self.__title_written == 0 :
|
if self.__title_written == 0 :
|
||||||
self.title += text
|
self.title += text
|
||||||
|
if links == True:
|
||||||
|
import re
|
||||||
|
text = re.sub(URL_PATTERN, _CLICKABLE, text)
|
||||||
self.htmllist[-1] += text
|
self.htmllist[-1] += text
|
||||||
|
|
||||||
def __empty_char(self):
|
def __empty_char(self):
|
||||||
@ -323,7 +334,7 @@ class HtmlDoc(BaseDoc, TextDoc):
|
|||||||
"""
|
"""
|
||||||
if text != "":
|
if text != "":
|
||||||
self._empty = 0
|
self._empty = 0
|
||||||
self.__write_text(text, mark)
|
self.__write_text(text, mark, links=links)
|
||||||
|
|
||||||
def write_title(self):
|
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
|
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
|
a link is clickable. HtmlDoc will show the html as pure text, so
|
||||||
no escaping will happen.
|
no escaping will happen.
|
||||||
|
links: bool, make URLs clickable if True
|
||||||
"""
|
"""
|
||||||
text = str(styledtext)
|
text = str(styledtext)
|
||||||
|
|
||||||
@ -469,7 +481,7 @@ class HtmlDoc(BaseDoc, TextDoc):
|
|||||||
#just dump the note out as it is. Adding markup would be dangerous
|
#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
|
# as it could destroy the html. If html code, one can do the
|
||||||
self.start_paragraph(style_name)
|
self.start_paragraph(style_name)
|
||||||
self.__write_text(text, markup=True)
|
self.__write_text(text, markup=True, links=links)
|
||||||
self.end_paragraph()
|
self.end_paragraph()
|
||||||
else:
|
else:
|
||||||
s_tags = styledtext.get_tags()
|
s_tags = styledtext.get_tags()
|
||||||
@ -502,7 +514,7 @@ class HtmlDoc(BaseDoc, TextDoc):
|
|||||||
self._empty = 1 # para is empty
|
self._empty = 1 # para is empty
|
||||||
if linenb > 1:
|
if linenb > 1:
|
||||||
self.htmllist[-1] += Html('br')
|
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
|
self._empty = 0 # para is not empty
|
||||||
linenb += 1
|
linenb += 1
|
||||||
if inpara == True:
|
if inpara == True:
|
||||||
@ -528,17 +540,31 @@ class HtmlDoc(BaseDoc, TextDoc):
|
|||||||
imdir = self._backend.datadirfull()
|
imdir = self._backend.datadirfull()
|
||||||
|
|
||||||
try:
|
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:
|
except:
|
||||||
LOG.warn(_("Could not create jpeg version of image %(name)s") %
|
LOG.warn(_("Could not create jpeg version of image %(name)s") %
|
||||||
{'name' : name})
|
{'name' : name})
|
||||||
return
|
return
|
||||||
|
|
||||||
if pos not in ["right", "left"] :
|
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)
|
border = '0', alt=alt)
|
||||||
else:
|
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)
|
border = '0', alt=alt, align=pos)
|
||||||
|
|
||||||
def page_break(self):
|
def page_break(self):
|
||||||
|
@ -1038,9 +1038,16 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
|
|||||||
(act_width, act_height) = ImgManip.image_actual_size(x_cm, y_cm, x, y)
|
(act_width, act_height) = ImgManip.image_actual_size(x_cm, y_cm, x, y)
|
||||||
|
|
||||||
if len(alt):
|
if len(alt):
|
||||||
self.cntnt.write('<draw:frame draw:style-name="%s" draw:name="caption_%s" text:anchor-type="paragraph" svg:y="0in" svg:width="%.2fcm" draw:z-index="34"> ' % (pos, tag, act_width))
|
self.cntnt.write(
|
||||||
self.cntnt.write('<draw:text-box fo:min-height="%.2fcm"> ' % act_height)
|
'<draw:frame draw:style-name="%s" ' % pos +
|
||||||
self.cntnt.write('<text:p text:style-name="%s">' % style_name)
|
'draw:name="caption_%s" ' % tag +
|
||||||
|
'text:anchor-type="paragraph" ' +
|
||||||
|
'svg:y="0in" ' +
|
||||||
|
'svg:width="%.2fcm" ' % act_width +
|
||||||
|
'draw:z-index="34"> ' +
|
||||||
|
'<draw:text-box fo:min-height="%.2fcm"> ' % act_height +
|
||||||
|
'<text:p text:style-name="%s">' % style_name
|
||||||
|
)
|
||||||
|
|
||||||
self.cntnt.write(
|
self.cntnt.write(
|
||||||
'<draw:frame draw:style-name="%s" ' % pos +
|
'<draw:frame draw:style-name="%s" ' % pos +
|
||||||
@ -1554,6 +1561,8 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
|
|||||||
entities. The _esc_map dictionary allows us to add our own
|
entities. The _esc_map dictionary allows us to add our own
|
||||||
mappings.
|
mappings.
|
||||||
"""
|
"""
|
||||||
|
text = escape(text, _esc_map)
|
||||||
|
|
||||||
if links == True:
|
if links == True:
|
||||||
text = re.sub(URL_PATTERN, _CLICKABLE, text)
|
text = re.sub(URL_PATTERN, _CLICKABLE, text)
|
||||||
|
|
||||||
@ -1572,7 +1581,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
|
|||||||
'text:string-value="%s" ' % key +
|
'text:string-value="%s" ' % key +
|
||||||
'text:outline-level="%d" />' % mark.level
|
'text:outline-level="%d" />' % mark.level
|
||||||
)
|
)
|
||||||
self.cntnt.write(escape(text, _esc_map))
|
self.cntnt.write(text)
|
||||||
|
|
||||||
def _write_manifest(self):
|
def _write_manifest(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user