bug #2402 : Line spacing for text not correct in CairoDoc

svn: r15839
This commit is contained in:
Benny Malengier 2010-08-31 07:52:11 +00:00
parent c2dc10471c
commit e24b184508

View File

@ -394,7 +394,7 @@ class GtkDocParagraph(GtkDocBaseElement):
_allowed_children = [] _allowed_children = []
# line spacing is not defined in ParagraphStyle # line spacing is not defined in ParagraphStyle
spacing = 2 spacingfractionfont = 0.2
def __init__(self, style, leader=None): def __init__(self, style, leader=None):
GtkDocBaseElement.__init__(self, style) GtkDocBaseElement.__init__(self, style)
@ -454,8 +454,7 @@ class GtkDocParagraph(GtkDocBaseElement):
layout.set_width(int(text_width * pango.SCALE)) layout.set_width(int(text_width * pango.SCALE))
# set paragraph properties # set paragraph properties
layout.set_wrap(pango.WRAP_WORD_CHAR) layout.set_wrap(pango.WRAP_WORD_CHAR)
layout.set_spacing(self.spacing * pango.SCALE)
layout.set_indent(int(f_indent * pango.SCALE)) layout.set_indent(int(f_indent * pango.SCALE))
layout.set_tabs(tabstops_to_tabarray(self._style.get_tabs(), dpi_x)) 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() font_style = self._style.get_font()
layout.set_font_description(fontstyle_to_fontdescription(font_style)) 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 text_height = height - t_margin - 2 * v_padding
# calculate where to cut the paragraph # calculate where to cut the paragraph
@ -484,7 +487,7 @@ class GtkDocParagraph(GtkDocBaseElement):
# if all paragraph fits we don't need to cut # if all paragraph fits we don't need to cut
if layout_height - spacing <= text_height: 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: if height - paragraph_height > b_margin:
paragraph_height += b_margin paragraph_height += b_margin
return (self, None), paragraph_height return (self, None), paragraph_height
@ -559,7 +562,7 @@ class GtkDocParagraph(GtkDocBaseElement):
self.__set_plaintext(self._plaintext.encode('utf-8')[:index]) self.__set_plaintext(self._plaintext.encode('utf-8')[:index])
self._style.set_bottom_margin(0) 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 return (self, new_paragraph), paragraph_height
def filterattr(self, attr, index): def filterattr(self, attr, index):
@ -589,7 +592,6 @@ class GtkDocParagraph(GtkDocBaseElement):
# set paragraph properties # set paragraph properties
layout.set_wrap(pango.WRAP_WORD_CHAR) layout.set_wrap(pango.WRAP_WORD_CHAR)
layout.set_spacing(self.spacing * pango.SCALE)
layout.set_indent(int(f_indent * pango.SCALE)) layout.set_indent(int(f_indent * pango.SCALE))
layout.set_tabs(tabstops_to_tabarray(self._style.get_tabs(), dpi_x)) 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() font_style = self._style.get_font()
layout.set_font_description(fontstyle_to_fontdescription(font_style)) 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 the text
layout.set_text(self._plaintext) layout.set_text(self._plaintext)
@ -615,12 +620,13 @@ class GtkDocParagraph(GtkDocBaseElement):
x = l_margin + h_padding x = l_margin + h_padding
if f_indent < 0: if f_indent < 0:
x += f_indent 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.set_source_rgb(*ReportUtils.rgb_color(font_style.get_color()))
cr.show_layout(layout) cr.show_layout(layout)
# calculate the full paragraph height # 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 # draw the borders
if self._style.get_top_border(): if self._style.get_top_border():
@ -1117,7 +1123,7 @@ class GtkDocText(GtkDocBaseElement):
_allowed_children = [] _allowed_children = []
# line spacing is not defined in ParagraphStyle # line spacing is not defined in ParagraphStyle
spacing = 0 spacingfractionfont = 0.2
def __init__(self, style, vertical_alignment, text, x, y, angle=0): def __init__(self, style, vertical_alignment, text, x, y, angle=0):
GtkDocBaseElement.__init__(self, style) GtkDocBaseElement.__init__(self, style)
@ -1135,8 +1141,6 @@ class GtkDocText(GtkDocBaseElement):
layout.set_width(-1) layout.set_width(-1)
# set paragraph properties # set paragraph properties
layout.set_spacing(self.spacing * pango.SCALE)
#
align = self._style.get_alignment_text() align = self._style.get_alignment_text()
if align == 'left': if align == 'left':
layout.set_alignment(pango.ALIGN_LEFT) layout.set_alignment(pango.ALIGN_LEFT)
@ -1151,6 +1155,9 @@ class GtkDocText(GtkDocBaseElement):
# #
font_style = self._style.get_font() font_style = self._style.get_font()
layout.set_font_description(fontstyle_to_fontdescription(font_style)) 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 the text
layout.set_markup(self._text) layout.set_markup(self._text)