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:
Brian Matherly
2011-07-12 03:30:58 +00:00
parent c9f0f2c8d7
commit bb6ad450e3
5 changed files with 76 additions and 23 deletions

View File

@@ -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'''<a href="\1">\1</a>'''
#------------------------------------------------------------------------
#
# 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):

View File

@@ -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('<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('<draw:text-box fo:min-height="%.2fcm"> ' % act_height)
self.cntnt.write('<text:p text:style-name="%s">' % style_name)
self.cntnt.write(
'<draw:frame draw:style-name="%s" ' % pos +
'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(
'<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
mappings.
"""
text = escape(text, _esc_map)
if links == True:
text = re.sub(URL_PATTERN, _CLICKABLE, text)
@@ -1572,7 +1581,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
'text:string-value="%s" ' % key +
'text:outline-level="%d" />' % mark.level
)
self.cntnt.write(escape(text, _esc_map))
self.cntnt.write(text)
def _write_manifest(self):
"""