From f89bfe0796a7329cb18da0911d718f02ea05d3c1 Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Fri, 17 Sep 2010 12:08:38 +0000 Subject: [PATCH] copyright Jakim Friant, ticket 4237: Line Styles in Report not Fully Supported svn: r15911 --- src/gen/plug/docgen/__init__.py | 3 +- src/gen/plug/docgen/graphicstyle.py | 34 ++++++++++++++++++ src/plugins/docgen/ODFDoc.py | 31 +++++++++++------ src/plugins/docgen/PSDrawDoc.py | 6 ++-- src/plugins/docgen/SvgDrawDoc.py | 53 +++++++++++++++-------------- src/plugins/lib/libcairodoc.py | 11 +++++- 6 files changed, 98 insertions(+), 40 deletions(-) diff --git a/src/gen/plug/docgen/__init__.py b/src/gen/plug/docgen/__init__.py index 01608dd7b..e359821a5 100644 --- a/src/gen/plug/docgen/__init__.py +++ b/src/gen/plug/docgen/__init__.py @@ -2,6 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2009 B. Malengier +# Copyright (C) 2010 Jakim Friant # # 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 @@ -32,7 +33,7 @@ from paragraphstyle import ParagraphStyle, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT,\ PARA_ALIGN_RIGHT, PARA_ALIGN_JUSTIFY from tablestyle import TableStyle, TableCellStyle 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 drawdoc import DrawDoc from graphdoc import GVDoc diff --git a/src/gen/plug/docgen/graphicstyle.py b/src/gen/plug/docgen/graphicstyle.py index f323cd85b..fd5b792ba 100644 --- a/src/gen/plug/docgen/graphicstyle.py +++ b/src/gen/plug/docgen/graphicstyle.py @@ -6,6 +6,7 @@ # Copyright (C) 2007 Brian G. Matherly # Copyright (C) 2009 Benny Malengier # Copyright (C) 2009 Gary Burton +# Copyright (C) 2010 Jakim Friant # # 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 @@ -54,6 +55,23 @@ log = logging.getLogger(".graphicstyle") #------------------------------------------------------------------------- SOLID = 0 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): 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): self.para_name = val diff --git a/src/plugins/docgen/ODFDoc.py b/src/plugins/docgen/ODFDoc.py index 6c4f162d5..87a26b6e3 100644 --- a/src/plugins/docgen/ODFDoc.py +++ b/src/plugins/docgen/ODFDoc.py @@ -79,8 +79,8 @@ from xml.sax.saxutils import escape # #------------------------------------------------------------------------- from gui.utils import open_file_with_default_application -from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, - FONT_SANS_SERIF, DASHED, PAPER_PORTRAIT, +from gen.plug.docgen import (BaseDoc, TextDoc, DrawDoc, graphicstyle, + FONT_SANS_SERIF, SOLID, PAPER_PORTRAIT, INDEX_TYPE_TOC, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT, INDEX_TYPE_ALP, PARA_ALIGN_RIGHT) from gen.plug.docgen.fontscale import string_width @@ -500,7 +500,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): '\n' + _AUTOMATIC_STYLES ) - + styles = self.get_style_sheet() for style_name in styles.get_draw_style_names(): @@ -519,23 +519,23 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): 'draw:marker-start="" ' 'draw:marker-start-width="0.0" ' 'draw:marker-end-width="0.0" ' - 'draw:stroke="solid" ' 'draw:textarea-horizontal-align="center" ' '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: wrt( 'draw:stroke="none" ' '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( + 'svg:fill-color="#%02x%02x%02x" ' + % style.get_color() + 'draw:fill-color="#%02x%02x%02x" ' % style.get_fill_color() + 'draw:shadow="hidden" ' @@ -1161,6 +1161,15 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): '\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('\n' % (line_style, dash_array[0], dash_array[0], dash_array[1] * 0.051)) + + # Current no leading number format for headers #wrtf('\n') @@ -1580,7 +1589,7 @@ class ODFDoc(BaseDoc, TextDoc, DrawDoc): self.cntnt.write( '\n' % s.get_line_width() - ) + line_out = '\n' ) - self.f.write( - '\n' % box_style.get_line_width() - ) + line_out = '