From e24b184508e8e90bb3c88c61238839b48a1c6b34 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Tue, 31 Aug 2010 07:52:11 +0000 Subject: [PATCH] bug #2402 : Line spacing for text not correct in CairoDoc svn: r15839 --- src/plugins/lib/libcairodoc.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/plugins/lib/libcairodoc.py b/src/plugins/lib/libcairodoc.py index 53a78fada..21e85a118 100644 --- a/src/plugins/lib/libcairodoc.py +++ b/src/plugins/lib/libcairodoc.py @@ -394,7 +394,7 @@ class GtkDocParagraph(GtkDocBaseElement): _allowed_children = [] # line spacing is not defined in ParagraphStyle - spacing = 2 + spacingfractionfont = 0.2 def __init__(self, style, leader=None): GtkDocBaseElement.__init__(self, style) @@ -454,8 +454,7 @@ class GtkDocParagraph(GtkDocBaseElement): layout.set_width(int(text_width * pango.SCALE)) # set paragraph properties - layout.set_wrap(pango.WRAP_WORD_CHAR) - layout.set_spacing(self.spacing * pango.SCALE) + layout.set_wrap(pango.WRAP_WORD_CHAR) layout.set_indent(int(f_indent * pango.SCALE)) layout.set_tabs(tabstops_to_tabarray(self._style.get_tabs(), dpi_x)) # @@ -473,6 +472,10 @@ class GtkDocParagraph(GtkDocBaseElement): # font_style = self._style.get_font() layout.set_font_description(fontstyle_to_fontdescription(font_style)) + #set line spacing based on font: + spacing = font_style.get_size() * self.spacingfractionfont + layout.set_spacing(int(round(spacing * pango.SCALE))) + text_height = height - t_margin - 2 * v_padding # calculate where to cut the paragraph @@ -484,7 +487,7 @@ class GtkDocParagraph(GtkDocBaseElement): # if all paragraph fits we don't need to cut if layout_height - spacing <= text_height: - paragraph_height = layout_height + t_margin + (2 * v_padding) + paragraph_height = layout_height + spacing +t_margin + (2 * v_padding) if height - paragraph_height > b_margin: paragraph_height += b_margin return (self, None), paragraph_height @@ -559,7 +562,7 @@ class GtkDocParagraph(GtkDocBaseElement): self.__set_plaintext(self._plaintext.encode('utf-8')[:index]) self._style.set_bottom_margin(0) - paragraph_height = endheight - startheight + t_margin + 2 * v_padding + paragraph_height = endheight - startheight + spacing + t_margin + 2 * v_padding return (self, new_paragraph), paragraph_height def filterattr(self, attr, index): @@ -589,7 +592,6 @@ class GtkDocParagraph(GtkDocBaseElement): # set paragraph properties layout.set_wrap(pango.WRAP_WORD_CHAR) - layout.set_spacing(self.spacing * pango.SCALE) layout.set_indent(int(f_indent * pango.SCALE)) layout.set_tabs(tabstops_to_tabarray(self._style.get_tabs(), dpi_x)) # @@ -605,6 +607,9 @@ class GtkDocParagraph(GtkDocBaseElement): # font_style = self._style.get_font() layout.set_font_description(fontstyle_to_fontdescription(font_style)) + #set line spacing based on font: + spacing = font_style.get_size() * self.spacingfractionfont + layout.set_spacing(int(round(spacing * pango.SCALE))) # layout the text layout.set_text(self._plaintext) @@ -615,12 +620,13 @@ class GtkDocParagraph(GtkDocBaseElement): x = l_margin + h_padding if f_indent < 0: x += f_indent - cr.move_to(x, t_margin + v_padding) + # 3/4 of the spacing is added above the text, 1/4 is added below + cr.move_to(x, t_margin + v_padding + spacing * 0.75) cr.set_source_rgb(*ReportUtils.rgb_color(font_style.get_color())) cr.show_layout(layout) # calculate the full paragraph height - height = layout_height + t_margin + 2*v_padding + b_margin + height = layout_height + spacing + t_margin + 2*v_padding + b_margin # draw the borders if self._style.get_top_border(): @@ -1117,7 +1123,7 @@ class GtkDocText(GtkDocBaseElement): _allowed_children = [] # line spacing is not defined in ParagraphStyle - spacing = 0 + spacingfractionfont = 0.2 def __init__(self, style, vertical_alignment, text, x, y, angle=0): GtkDocBaseElement.__init__(self, style) @@ -1135,8 +1141,6 @@ class GtkDocText(GtkDocBaseElement): layout.set_width(-1) # set paragraph properties - layout.set_spacing(self.spacing * pango.SCALE) - # align = self._style.get_alignment_text() if align == 'left': layout.set_alignment(pango.ALIGN_LEFT) @@ -1151,6 +1155,9 @@ class GtkDocText(GtkDocBaseElement): # font_style = self._style.get_font() layout.set_font_description(fontstyle_to_fontdescription(font_style)) + #set line spacing based on font: + spacing = font_style.get_size() * self.spacingfractionfont + layout.set_spacing(int(round(spacing * pango.SCALE))) # layout the text layout.set_markup(self._text)