Patch from Adam Stein <adam@csh.rit.edu>: Add support for links and cropped images in ODF document output. Also related to: http://www.gramps-project.org/bugs/view.php?id=4774
svn: r17451
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#
|
||||
# Copyright (C) 2009 B. Malengier
|
||||
# Copyright (C) 2010 Jakim Friant
|
||||
# Copyright (C) 2011 Adam Stein <adam@csh.rit.edu>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -34,6 +35,6 @@ from paragraphstyle import ParagraphStyle, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT,\
|
||||
from tablestyle import TableStyle, TableCellStyle
|
||||
from stylesheet import StyleSheetList, StyleSheet, SheetParser
|
||||
from graphicstyle import GraphicsStyle, SOLID, DASHED, DOTTED
|
||||
from textdoc import TextDoc, IndexMark,INDEX_TYPE_ALP, INDEX_TYPE_TOC
|
||||
from textdoc import TextDoc, IndexMark,INDEX_TYPE_ALP, INDEX_TYPE_TOC, URL_PATTERN
|
||||
from drawdoc import DrawDoc
|
||||
from graphdoc import GVDoc
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
# Copyright (C) 2009 Benny Malengier
|
||||
# Copyright (C) 2009 Gary Burton
|
||||
# Copyright (C) 2010 Peter Landgren
|
||||
# Copyright (C) 2011 Adam Stein <adam@csh.rit.edu>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -47,6 +48,13 @@
|
||||
import logging
|
||||
log = logging.getLogger(".textdoc")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# URL string pattern
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
URL_PATTERN = r'''(((https?|mailto):)(//([^/?#"]*))?([^?#"]*)(\?([^#"]*))?(#([^"]*))?)'''
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# IndexMark types
|
||||
@@ -160,13 +168,14 @@ class TextDoc(object):
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def write_text(self, text, mark=None):
|
||||
def write_text(self, text, mark=None, links=False):
|
||||
"""
|
||||
Writes the text in the current paragraph. Should only be used after a
|
||||
start_paragraph and before an end_paragraph.
|
||||
|
||||
@param text: text to write.
|
||||
@param mark: IndexMark to use for indexing (if supported)
|
||||
@param links: make URLs in the text clickable (if supported)
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -194,17 +203,18 @@ class TextDoc(object):
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def write_endnotes_ref(self, text, style_name):
|
||||
def write_endnotes_ref(self, text, style_name, links=False):
|
||||
"""
|
||||
Writes the note's text and take care of paragraphs,
|
||||
|
||||
@param text: text to write.
|
||||
@param style_name: style to be used.
|
||||
@param links: make URLs in the text clickable (if supported)
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def write_styled_note(self, styledtext, format, style_name,
|
||||
contains_html=False):
|
||||
contains_html=False, links=False):
|
||||
"""
|
||||
Convenience function to write a styledtext to the cairo doc.
|
||||
styledtext : assumed a StyledText object to write
|
||||
@@ -214,6 +224,7 @@ class TextDoc(object):
|
||||
If contains_html=True, then the textdoc is free to handle that in
|
||||
some way. Eg, a textdoc could remove all tags, or could make sure
|
||||
a link is clickable.
|
||||
links: bool, make URLs in the text clickable (if supported)
|
||||
|
||||
overwrite this method if the backend supports styled notes
|
||||
"""
|
||||
@@ -252,7 +263,7 @@ class TextDoc(object):
|
||||
else:
|
||||
self.write_text(piece)
|
||||
|
||||
def add_media_object(self, name, align, w_cm, h_cm, alt=''):
|
||||
def add_media_object(self, name, align, w_cm, h_cm, alt='', style_name=None, crop=None):
|
||||
"""
|
||||
Add a photo of the specified width (in centimeters).
|
||||
|
||||
@@ -262,6 +273,8 @@ class TextDoc(object):
|
||||
@param w_cm: width in centimeters
|
||||
@param h_cm: height in centimeters
|
||||
@param alt: an alternative text to use. Useful for eg html reports
|
||||
@param style_name: style to use for captions
|
||||
@param crop: image cropping parameters
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -293,3 +306,4 @@ class TextDoc(object):
|
||||
so that docgen ntypes are not required to have this.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# Copyright (C) 2007 Brian G. Matherly
|
||||
# Copyright (C) 2010 Peter Landgren
|
||||
# Copyright (C) 2010 Jakim Friant
|
||||
# Copyright (C) 2011 Adam Stein <adam@csh.rit.edu>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@@ -90,7 +91,7 @@ def cite_source(bibliography, obj):
|
||||
txt += key
|
||||
return txt
|
||||
|
||||
def write_endnotes(bibliography, database, doc, printnotes=False):
|
||||
def write_endnotes(bibliography, database, doc, printnotes=False, links=False):
|
||||
"""
|
||||
Write all the entries in the bibliography as endnotes.
|
||||
|
||||
@@ -103,6 +104,8 @@ def write_endnotes(bibliography, database, doc, printnotes=False):
|
||||
@param printnotes: Indicate if the notes attached to a source must be
|
||||
written too.
|
||||
@type printnotes: bool
|
||||
@param links: Indicate if URL links should be makde 'clickable'.
|
||||
@type links: bool
|
||||
"""
|
||||
if bibliography.get_citation_count() == 0:
|
||||
return
|
||||
@@ -121,7 +124,7 @@ def write_endnotes(bibliography, database, doc, printnotes=False):
|
||||
|
||||
src_txt = _format_source_text(source)
|
||||
|
||||
doc.write_text(src_txt)
|
||||
doc.write_text(src_txt, links=links)
|
||||
doc.end_paragraph()
|
||||
|
||||
ref_list = citation.get_ref_list()
|
||||
@@ -136,7 +139,7 @@ def write_endnotes(bibliography, database, doc, printnotes=False):
|
||||
first = False
|
||||
else:
|
||||
reflines += ('\n%s' % txt)
|
||||
doc.write_endnotes_ref(reflines,'Endnotes-Ref')
|
||||
doc.write_endnotes_ref(reflines,'Endnotes-Ref', links=links)
|
||||
|
||||
if printnotes:
|
||||
note_list = source.get_note_list()
|
||||
@@ -151,7 +154,8 @@ def write_endnotes(bibliography, database, doc, printnotes=False):
|
||||
doc.write_styled_note(note.get_styledtext(),
|
||||
note.get_format(),'Endnotes-Notes',
|
||||
contains_html= note.get_type() \
|
||||
== NoteType.HTML_CODE)
|
||||
== NoteType.HTML_CODE,
|
||||
links=links)
|
||||
ind += 1
|
||||
|
||||
def _format_source_text(source):
|
||||
|
||||
Reference in New Issue
Block a user