Fix problem when markup spans two paragraph in the note: make sure
styling stops at paragraph if backend splits the note in pieces to print Fix problem with paragraphs written in cells. Paragraphs should not divide as cells and rows are not allowed to divide. This forces table to be divided, and full paragraph to be written svn: r11969
This commit is contained in:
parent
4f1aacc75d
commit
7fefd970c7
@ -1652,10 +1652,18 @@ class TextDoc:
|
||||
return None
|
||||
return ('', '')
|
||||
|
||||
def _add_markup_from_styled(self, text, s_tags):
|
||||
def _add_markup_from_styled(self, text, s_tags, split=''):
|
||||
"""
|
||||
Input is plain text, output is text with markup added according to the
|
||||
s_tags which are assumed to be styledtexttags.
|
||||
When split is given the text will be split over the value given, and
|
||||
tags applied in such a way that it the text can be safely splitted in
|
||||
pieces along split
|
||||
|
||||
@param text : str, a piece of text
|
||||
@param s_tags : styledtexttags that must be applied to the text
|
||||
@param split : str, optional. A string along which the output can
|
||||
be safely split without breaking the styling.
|
||||
As adding markup means original text must be escaped, ESCAPE_FUNC is
|
||||
used
|
||||
This can be used to convert the text of a styledtext to the format
|
||||
@ -1690,9 +1698,29 @@ class TextDoc:
|
||||
keylist = [x for x in keylist if x<=len(text)]
|
||||
opentags = []
|
||||
otext = u"" #the output, text with markup
|
||||
lensplit = len(split)
|
||||
for pos in keylist:
|
||||
#write text up to tag
|
||||
if pos > start:
|
||||
if split:
|
||||
#make sure text can split
|
||||
splitpos = text[start:pos].find(split)
|
||||
while splitpos <> -1:
|
||||
otext += self.ESCAPE_FUNC()(text[start:splitpos])
|
||||
#close open tags
|
||||
opentags.reverse()
|
||||
for opentag in opentags:
|
||||
otext += opentag[1]
|
||||
opentags.reverse()
|
||||
#add split text
|
||||
otext += self.ESCAPE_FUNC()(split)
|
||||
#open the tags again
|
||||
for opentag in opentags:
|
||||
otext += opentag[0]
|
||||
#obtain new values
|
||||
start = start + splitpos + lensplit
|
||||
splitpos = text[start:pos].find(split)
|
||||
|
||||
otext += self.ESCAPE_FUNC()(text[start:pos])
|
||||
#write out tags
|
||||
for tag in tagspos[pos]:
|
||||
@ -1711,6 +1739,7 @@ class TextDoc:
|
||||
for opentag in opentags:
|
||||
otext += opentag[0]
|
||||
start = pos
|
||||
#add remainder of text, no markup present there
|
||||
otext += self.ESCAPE_FUNC()(text[start:end])
|
||||
|
||||
#opentags should be empty. If not, user gave tags on positions that
|
||||
|
@ -446,8 +446,8 @@ class GtkDocParagraph(GtkDocBaseElement):
|
||||
text_height = height - t_margin - 2 * v_padding
|
||||
line_per_height = text_height / line_height
|
||||
|
||||
# if nothing fits
|
||||
if line_per_height < 1:
|
||||
# if nothing fits return now with result if not a cell (undivisable)
|
||||
if line_per_height < 1 and not self._parent._type == 'CELL':
|
||||
return (None, self), 0
|
||||
|
||||
# calculate where to cut the paragraph
|
||||
@ -456,7 +456,10 @@ class GtkDocParagraph(GtkDocBaseElement):
|
||||
line_count = layout.get_line_count()
|
||||
|
||||
# if all paragraph fits we don't need to cut
|
||||
if line_count <= line_per_height:
|
||||
# if paragraph part of a cell, we do not divide, table must be split,
|
||||
# as rows and cells do not divide ...
|
||||
# ==> note: this means the user must not make one page paragraphs!
|
||||
if line_count <= line_per_height or self._parent._type == 'CELL':
|
||||
paragraph_height = (layout_height + t_margin + (2 * v_padding))
|
||||
if height - paragraph_height > b_margin:
|
||||
paragraph_height += b_margin
|
||||
@ -475,7 +478,7 @@ class GtkDocParagraph(GtkDocBaseElement):
|
||||
self._style.set_bottom_margin(0)
|
||||
|
||||
# FIXME do we need to return the proper height???
|
||||
#paragraph_height = line_height * line_count + t_margin + 2 * v_padding
|
||||
# paragraph_height = line_height * line_count + t_margin + 2 * v_padding
|
||||
paragraph_height = 0
|
||||
return (self, new_paragraph), paragraph_height
|
||||
|
||||
@ -683,7 +686,7 @@ class GtkDocTableCell(GtkDocBaseElement):
|
||||
# calculate real available width
|
||||
width -= 2 * h_padding
|
||||
|
||||
# calculate height of each children
|
||||
# calculate height of each child
|
||||
cell_height = 0
|
||||
for child in self._children:
|
||||
(e1, e2), child_height = child.divide(layout, width, height,
|
||||
@ -1222,7 +1225,8 @@ class CairoDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
|
||||
text = str(styledtext)
|
||||
|
||||
s_tags = styledtext.get_tags()
|
||||
markuptext = self._add_markup_from_styled(text, s_tags)
|
||||
#FIXME: following split should be regex to match \n\s*\n instead?
|
||||
markuptext = self._add_markup_from_styled(text, s_tags, split='\n\n')
|
||||
|
||||
if format == 1:
|
||||
#preformatted, retain whitespace. Cairo retains \n automatically,
|
||||
|
Loading…
Reference in New Issue
Block a user