copyright Jakim Friant, ticket 4237: Line Styles in Report not Fully Supported

svn: r15911
This commit is contained in:
Benny Malengier
2010-09-17 12:08:38 +00:00
parent 7efc0f77cf
commit f89bfe0796
6 changed files with 98 additions and 40 deletions

View File

@@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2009 B. Malengier # Copyright (C) 2009 B. Malengier
# Copyright (C) 2010 Jakim Friant
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@@ -32,7 +33,7 @@ from paragraphstyle import ParagraphStyle, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT,\
PARA_ALIGN_RIGHT, PARA_ALIGN_JUSTIFY PARA_ALIGN_RIGHT, PARA_ALIGN_JUSTIFY
from tablestyle import TableStyle, TableCellStyle from tablestyle import TableStyle, TableCellStyle
from stylesheet import StyleSheetList, StyleSheet, SheetParser from stylesheet import StyleSheetList, StyleSheet, SheetParser
from graphicstyle import GraphicsStyle, SOLID, DASHED 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
from drawdoc import DrawDoc from drawdoc import DrawDoc
from graphdoc import GVDoc from graphdoc import GVDoc

View File

@@ -6,6 +6,7 @@
# Copyright (C) 2007 Brian G. Matherly # Copyright (C) 2007 Brian G. Matherly
# Copyright (C) 2009 Benny Malengier # Copyright (C) 2009 Benny Malengier
# Copyright (C) 2009 Gary Burton # Copyright (C) 2009 Gary Burton
# Copyright (C) 2010 Jakim Friant
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@@ -54,6 +55,23 @@ log = logging.getLogger(".graphicstyle")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
SOLID = 0 SOLID = 0
DASHED = 1 DASHED = 1
DOTTED = 2
# Notes about adding new line styles:
# 1) the first style is used when an invalid style is specified by the report
# 2) the style names are used by the ODF generator and should be unique
# 3) the line style constants above need to be imported in the
# gen.plug.docgen.__init__ file so they can be used in a report add-on
line_style_names = ('solid', 'dashed', 'dotted')
_DASH_ARRAY = [ [1, 0], [2, 4], [1, 2] ]
def get_line_style_by_name(style_name):
which = 0
for (idx, sn) in enumerate(line_style_names):
if sn == style_name:
which = idx
break
return _DASH_ARRAY[which]
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@@ -106,6 +124,22 @@ class GraphicsStyle(object):
def set_line_style(self, val): def set_line_style(self, val):
self.lstyle = val self.lstyle = val
def get_dash_style(self, val = None):
if val is None:
val = self.lstyle
if val >= 0 and val < len(_DASH_ARRAY):
return _DASH_ARRAY[val]
else:
return _DASH_ARRAY[0]
def get_dash_style_name(self, val=None):
if val is None:
val = self.lstyle
if val >= 0 and val < len(line_style_names):
return line_style_names[val]
else:
return line_style_names[0]
def set_paragraph_style(self, val): def set_paragraph_style(self, val):
self.para_name = val self.para_name = val

View File

@@ -79,8 +79,8 @@ from xml.sax.saxutils import escape
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gui.utils import open_file_with_default_application from gui.utils import open_file_with_default_application
from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, graphicstyle,
FONT_SANS_SERIF, DASHED, PAPER_PORTRAIT, FONT_SANS_SERIF, SOLID, PAPER_PORTRAIT,
INDEX_TYPE_TOC, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT, INDEX_TYPE_TOC, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT,
INDEX_TYPE_ALP, PARA_ALIGN_RIGHT) INDEX_TYPE_ALP, PARA_ALIGN_RIGHT)
from gen.plug.docgen.fontscale import string_width from gen.plug.docgen.fontscale import string_width
@@ -519,23 +519,23 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
'draw:marker-start="" ' 'draw:marker-start="" '
'draw:marker-start-width="0.0" ' 'draw:marker-start-width="0.0" '
'draw:marker-end-width="0.0" ' 'draw:marker-end-width="0.0" '
'draw:stroke="solid" '
'draw:textarea-horizontal-align="center" ' 'draw:textarea-horizontal-align="center" '
'draw:textarea-vertical-align="middle" ' 'draw:textarea-vertical-align="middle" '
) )
if style.get_line_style() != SOLID:
#wrt('svg:fill-color="#ff0000" ')
wrt('draw:stroke="dash" draw:stroke-dash="gramps_%s" ' % style.get_dash_style_name())
else:
wrt('draw:stroke="solid" ')
else: else:
wrt( wrt(
'draw:stroke="none" ' 'draw:stroke="none" '
'draw:stroke-color="#000000" ' 'draw:stroke-color="#000000" '
) )
if style.get_line_style() == DASHED:
wrt('svg:fill-color="#cccccc" ')
else:
wrt('svg:fill-color="#%02x%02x%02x" '
% style.get_color())
wrt( wrt(
'svg:fill-color="#%02x%02x%02x" '
% style.get_color() +
'draw:fill-color="#%02x%02x%02x" ' 'draw:fill-color="#%02x%02x%02x" '
% style.get_fill_color() + % style.get_fill_color() +
'draw:shadow="hidden" ' 'draw:shadow="hidden" '
@@ -1161,6 +1161,15 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
'</style:style>\n' '</style:style>\n'
) )
# Dash lengths are based on the OpenOffice Ultrafine Dashed line style.
for line_style in graphicstyle.line_style_names:
dash_array = graphicstyle.get_line_style_by_name(line_style)
wrtf('<draw:stroke-dash draw:name="gramps_%s" draw:style="rect" '
'draw:dots1="%d" draw:dots1-length="0.102cm" '
'draw:dots2="%d" draw:dots2-length="0.102cm" '
'draw:distance="%5.3fcm" />\n' % (line_style, dash_array[0], dash_array[0], dash_array[1] * 0.051))
# Current no leading number format for headers # Current no leading number format for headers
#wrtf('<text:outline-style>\n') #wrtf('<text:outline-style>\n')
@@ -1580,7 +1589,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc):
self.cntnt.write( self.cntnt.write(
'<draw:line text:anchor-type="paragraph" ' + '<draw:line text:anchor-type="paragraph" ' +
'draw:z-index="3" ' + 'draw:z-index="3" ' +
'draw:text-style-name="%s" ' % style + 'draw:style-name="%s" ' % style +
'svg:x1="%.2fcm" ' % x1 + 'svg:x1="%.2fcm" ' % x1 +
'svg:y1="%.2fcm" ' % y1 + 'svg:y1="%.2fcm" ' % y1 +
'svg:x2="%.2fcm" ' % x2 + 'svg:x2="%.2fcm" ' % x2 +

View File

@@ -269,7 +269,8 @@ class PSDrawDoc(BaseDoc, DrawDoc):
if stype.get_line_style() == SOLID: if stype.get_line_style() == SOLID:
self.file.write('[] 0 setdash\n') self.file.write('[] 0 setdash\n')
else: else:
self.file.write('[2 4] 0 setdash\n') dash_style = stype.get_dash_style(stype.get_line_style())
self.file.write('[%s] 0 setdash\n' % (" ".join([str(d) for d in dash_style])))
point = path[0] point = path[0]
x1 = point[0] + self.paper.get_left_margin() x1 = point[0] + self.paper.get_left_margin()
@@ -309,7 +310,8 @@ class PSDrawDoc(BaseDoc, DrawDoc):
if stype.get_line_style() == SOLID: if stype.get_line_style() == SOLID:
self.file.write('[] 0 setdash\n') self.file.write('[] 0 setdash\n')
else: else:
self.file.write('[2 4] 0 setdash\n') dash_style = stype.get_dash_style(stype.get_line_style())
self.file.write('[%s] 0 setdash\n' % (" ".join([str(d) for d in dash_style])))
self.file.write( self.file.write(
'2 setlinecap\n' + '2 setlinecap\n' +

View File

@@ -3,6 +3,7 @@
# #
# Copyright (C) 2000-2006 Donald N. Allingham # Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2007-2009 Brian G. Matherly # Copyright (C) 2007-2009 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
@@ -38,7 +39,7 @@ import StringIO
# Gramps modules # Gramps modules
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gen.plug.docgen import BaseDoc, DrawDoc, FONT_SANS_SERIF from gen.plug.docgen import BaseDoc, DrawDoc, SOLID, FONT_SANS_SERIF
import Errors import Errors
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
@@ -153,26 +154,27 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
s = style_sheet.get_draw_style(style) s = style_sheet.get_draw_style(style)
self.f.write( line_out = '<line x1="%4.2fcm" y1="%4.2fcm" ' % (x1, y1)
'<line x1="%4.2fcm" y1="%4.2fcm" ' % (x1, y1) + line_out += 'x2="%4.2fcm" y2="%4.2fcm" ' % (x2, y2)
'x2="%4.2fcm" y2="%4.2fcm" ' % (x2, y2) + line_out += 'style="stroke:#%02x%02x%02x; ' % s.get_color()
'style="stroke:#%02x%02x%02x; ' % s.get_color() + if s.get_line_style() != SOLID:
'stroke-width:%.2fpt;"/>\n' % s.get_line_width() line_out += 'stroke-dasharray: %s; ' % (",".join([str(d) for d in s.get_dash_style()]))
) line_out += 'stroke-width:%.2fpt;"/>\n' % s.get_line_width()
self.f.write(line_out)
def draw_path(self, style, path): def draw_path(self, style, path):
style_sheet = self.get_style_sheet() style_sheet = self.get_style_sheet()
stype = style_sheet.get_draw_style(style) stype = style_sheet.get_draw_style(style)
point = path[0] point = path[0]
self.f.write( line_out = '<polygon fill="#%02x%02x%02x"' % stype.get_fill_color()
'<polygon fill="#%02x%02x%02x"' % stype.get_fill_color() + line_out += ' style="stroke:#%02x%02x%02x; ' % stype.get_color()
' style="stroke:#%02x%02x%02x; ' % stype.get_color() + if stype.get_line_style() != SOLID:
' stroke-width:%.2fpt;"' % stype.get_line_width() + line_out += 'stroke-dasharray: %s; ' % (",".join([str(d) for d in stype.get_dash_style()]))
' points="%.2f,%.2f' line_out += ' stroke-width:%.2fpt;"' % stype.get_line_width()
% units((point[0]+self.paper.get_left_margin(), line_out += ' points="%.2f,%.2f' % units((point[0]+self.paper.get_left_margin(),
point[1]+self.paper.get_top_margin())) point[1]+self.paper.get_top_margin()))
) self.f.write(line_out)
for point in path[1:]: for point in path[1:]:
self.f.write( self.f.write(
' %.2f,%.2f' ' %.2f,%.2f'
@@ -198,16 +200,17 @@ class SvgDrawDoc(BaseDoc, DrawDoc):
'style="fill:#808080; stroke:#808080; stroke-width:1;"/>\n' 'style="fill:#808080; stroke:#808080; stroke-width:1;"/>\n'
) )
self.f.write( line_out = '<rect '
'<rect ' line_out += 'x="%4.2fcm" ' % x
'x="%4.2fcm" ' % x + line_out += 'y="%4.2fcm" ' % y
'y="%4.2fcm" ' % y + line_out += 'width="%4.2fcm" ' % w
'width="%4.2fcm" ' % w + line_out += 'height="%4.2fcm" ' % h
'height="%4.2fcm" ' % h + line_out += 'style="fill:#%02x%02x%02x; ' % box_style.get_fill_color()
'style="fill:#%02x%02x%02x; ' % box_style.get_fill_color() + line_out += 'stroke:#%02x%02x%02x; ' % box_style.get_color()
'stroke:#%02x%02x%02x; ' % box_style.get_color() + if box_style.get_line_style() != SOLID:
'stroke-width:%f;"/>\n' % box_style.get_line_width() line_out += 'stroke-dasharray: %s; ' % (",".join([str(d) for d in box_style.get_dash_style()]))
) line_out += 'stroke-width:%f;"/>\n' % box_style.get_line_width()
self.f.write(line_out)
if text: if text:
para_name = box_style.get_paragraph_style() para_name = box_style.get_paragraph_style()

View File

@@ -41,7 +41,7 @@ from math import radians
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, ParagraphStyle, from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, ParagraphStyle,
TableCellStyle, FONT_SANS_SERIF, FONT_SERIF, TableCellStyle, SOLID, FONT_SANS_SERIF, FONT_SERIF,
FONT_MONOSPACE, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT) FONT_MONOSPACE, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT)
from gen.plug.report import utils as ReportUtils from gen.plug.report import utils as ReportUtils
from Errors import PluginError from Errors import PluginError
@@ -1032,6 +1032,9 @@ class GtkDocLine(GtkDocBaseElement):
cr.set_source_rgb(*line_color) cr.set_source_rgb(*line_color)
cr.set_line_width(self._style.get_line_width()) cr.set_line_width(self._style.get_line_width())
# TODO line style # TODO line style
line_style = self._style.get_line_style()
if line_style != SOLID:
cr.set_dash(self._style.get_dash_style(line_style), 0)
cr.move_to(*start) cr.move_to(*start)
cr.line_to(*end) cr.line_to(*end)
cr.stroke() cr.stroke()
@@ -1065,6 +1068,9 @@ class GtkDocPolygon(GtkDocBaseElement):
cr.set_source_rgb(*path_stroke_color) cr.set_source_rgb(*path_stroke_color)
cr.set_line_width(self._style.get_line_width()) cr.set_line_width(self._style.get_line_width())
# TODO line style # TODO line style
line_style = self._style.get_line_style()
if line_style != SOLID:
cr.set_dash(self._style.get_dash_style(line_style), 0)
cr.stroke() cr.stroke()
cr.restore() cr.restore()
@@ -1097,6 +1103,9 @@ class GtkDocBox(GtkDocBaseElement):
cr.set_line_width(self._style.get_line_width()) cr.set_line_width(self._style.get_line_width())
# TODO line style # TODO line style
line_style = self._style.get_line_style()
if line_style != SOLID:
cr.set_dash(self._style.get_dash_style(line_style), 0)
if self._style.get_shadow(): if self._style.get_shadow():
shadow_x = box_x + self._style.get_shadow_space() * dpi_x / 2.54 shadow_x = box_x + self._style.get_shadow_space() * dpi_x / 2.54